我有javascript對象的像的數組以下:更新對象的陣列中的JavaScript
var food = [
{id: 1, name: 'Apples', owned: true },
{id: 2, name: 'Oranges', owned: false },
{id: 3, name: 'Bananas', owned: true }
];
然後我接收與下列數據的另一數組:
var newFood = [
{id: 1, name: 'Peas'},
{id: 2, name: 'Oranges'},
{id: 3, name: 'Bananas'},
{id: 4, name: 'Grapefruits'}
];
如何更新的以前的food
數組中有新的信息newFeed
,沒有覆蓋原來的owned
屬性,同時增加owned: false
到任何新的對象?
請記住,這是純javascript,而不是jQuery。