I don't know why in my result for some items, the value is wrong.
var myArray = [{
item: "my apple 1",
value: 1
}, {
item: "my carrot",
value: 2
}, {
item: "my banana",
value: 3
}, {
item: "my potatoe",
value: 4
}, {
item: "my apple 2",
value: 0
}];
var MyArrayDefinition = [{
item: "my apple 1",
color: "red",
group: "fruit",
score: 1
}, {
item: "my carrot",
color: "orange",
group: "vegetable",
score: 0
}, {
item: "my banana",
color: "yellow",
group: "fruit",
score: 1
}, {
item: "my apple 2",
color: "red",
group: "fruit",
score: 0
}, {
item: "my potatoe",
color: "yellow",
group: "vegetable",
score: 0
}, ]
this is my function but the result is strange for the item "my apple 2"
var result = [];
myArray.forEach((itm, i) => {
result.push(Object.assign({}, itm, MyArrayDefinition[i]));
I'd like
[{
item: "my apple 1",
color: "red",
group: "fruit",
score: 1,
value: 1
}, {
item: "my carrot",
color: "orange",
group: "vegetable",
score: 0,
value: 2
}, {
item: "my banana",
color: "yellow",
group: "fruit",
score: 1,
value: 3
}, {
item: "my apple 2",
color: "red",
group: "fruit",
score: 0,
value: 0
}, {
item: "my potatoe",
color: "yellow",
group: "vegetable",
score: 0,
value: 4
}];