I can't add a key value pair to my array objects:
const arr = [{'a' :1, 'b':2},{'a':2, 'b':4}]
arr.map( item => {item.price = 1
document.getElementById("body").innerHTML += 'a : '+ item.price + ' ' });
I want arr to be :
{'a' :1, 'b':2, 'price' : 1},{'a':2, 'b':4, 'price' : 1}
documentif you only want to edit the array?mapneeds to return a new item.item.price = 1will amend the incoming item, and then return1, making the array[1,1]