Arun
Arun

Reputation: 21

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

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

This print the below output as an array

So the output should be.

0
: 
{data: 'test'}

Upvotes: 0

Views: 48

Answers (1)

Salketer
Salketer

Reputation: 15711

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

Upvotes: 1

Related Questions