這裏是我的代碼如何在javascript中刪除數組對象項?
var array = [{ id: 1, name: 'test' }, { id: 2, name: 'test2' }];
我需要上述陣列像下面
[{ name: 'test' }, { name: 'test2' }]
我用delete
array.forEach(function(arr, i) {
delete array[i].id;
});
console.log(array);
輸出嘗試作爲
[ { id: 1, name: 'test' },
{ id: 2, name: 'test2'} ]
改變但它不會刪除id
項目。如何刪除數組對象項?
我在節點v0.8中使用這個。
似乎工作正常:http://jsfiddle.net/AbdiasSoftware/fPJ2u/(?)在FF和Chrome中測試。沒有身份證在我的控制檯。 – K3N
它似乎在螢火蟲工作正常。 – mohkhan
@ Ken-AbdiasSoftware它不在客戶端,而是在服務器端使用節點** v0.8 **。 –