For several hours I've been searching on SO and trying to solve this: I have an array with objects. Each object has a key/value pair. I want to change the values of a certain key and store this in a new array.
Please have a look at this stackblitz
data:any[] = [
{ color: "brown", nr: 1},
{ color: "red", nr: 2},
{ color: "green", nr: 3}
]
newData: any[];
text() {
const array = [];
for (let i = 0; i < this.data.length; i++) {
this.data['nr'] = i * 2;
this.data['color'] = "yellow";
array.push(this.data[i]);
console.log(this.data[i]);
}
this.newData = array;
console.log(array);
}
I expect the newData array would have the new values, but no success. Obviously I am doing something wrong. Has anyone a clue?
this.datais an array...it has no propertiesnrorcolor...it's elements do