Why map is changin' the old array numbers
? I don't want to change the old array, I want to edit it (key * 2
) and put it in new array roots
. Can someone explain what the problem is?
var numbers = [{key:1,prop:"ok"}, {key:2,prop:"ok"}, {key:3,prop:"ok"}];
var roots = numbers.map(index => {
index.key = index.key * 2
return index
})
console.log('numbers', numbers)
console.log('roots', roots)