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

How to Update array value

I need to update my array value of key => icon into new array with another array key => icon

TS:

This is one of my array

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

this.diff = this.arrayVal;
console.log(this.diff);

This print the below output as an array

So the output should be.

0
: 
{data: 'test'}

>Solution :

You can loop through one array and get the other arrays’ value using the index.

const arr = [{
    icon: 'chevron-left'
  },
  {
    icon: 'chevron-right'
  },
];

const arr2 = [{
    icon: 'fas fa-<insert icon>',
    text: 'file1'
  },
  {
    icon: 'fas fa-<insert icon>',
    text: 'file2'
  }
];


console.log(arr2.map((v, k) => {
v.icon = v.icon.replace('<insert icon>', arr[k].icon);
return v;
}));
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