Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Do javascript/react have double arrow operator inside array?

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading