Home > Net >  Do javascript/react have double arrow operator inside array?
Do javascript/react have double arrow operator inside array?

Time:06-28

I have array like this:

const arr2 = [
    one => {
      'Hello';
    },
    two => {
      'Answer';
    },
    three => {
      'LOREM IPSUM';
    },
  ];

If javascript have arrow operator inside array then how can i push value at one or at two.

CodePudding user response:

const arr2 = [
    one => {
      'Hello';
    },
    two => {
      'Answer';
    },
    three => {
      'LOREM IPSUM';
    },
  ];

The one above is basically an array of arrow functions.

so if you do arr2[0] it will print

one => {
      'Hello';
    }

If you wanna do normal push and pop, you can do the same as what you do with arrays in JS

But by your question of double arrow operator , im assuming you wanna have to change values at particular index.

You can always do by arr2[1] = someFunc you wanna assign

Update:

this is what i did and this is the console.log for the same:

const arr2 = [
    one => {
      'Hello';
    },
    two => {
      'Answer';
    },
    three => {
      'LOREM IPSUM';
    },
  ];
  
  arr2.push("hey")
  arr2[1] = "what is this even"
  
  console.log(arr2)

/** [one => {
    'Hello';
  }, "what is this even", three => {
    'LOREM IPSUM';
  }, "hey"] **/

Hope it clears :)

Do let me know in case if any concerns

  • Related