Home > Net >  How to Update array value
How to Update array value

Time:11-29

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

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

This print the below output as an array

So the output should be.

0
: 
{data: 'test'}

CodePudding user response:

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;
}));

  • Related