我一直在嘗試幾種方法如何找到一個數組中的對象,其中ID = var,如果找到,從數組中刪除對象並返回新數組的物體。JavaScript找到並刪除基於鍵值的數組中的對象
數據:
[
{"id":"88","name":"Lets go testing"},
{"id":"99","name":"Have fun boys and girls"},
{"id":"108","name":"You are awesome!"}
]
我能夠搜索到使用jQuery的grep $數組;
var id = 88;
var result = $.grep(data, function(e){
return e.id == id;
});
但我怎麼能刪除整個對象時,ID = = 88,並返回這樣的數據:
數據:
[
{"id":"99","name":"Have fun boys and girls"},
{"id":"108","name":"You are awesome!"}
]
如何使用'切片'功能和一點'for'循環? –
當然,但是,我寫這個問題的原因,是因爲我卡住了;)任何片段? – Tom
檢查這個帖子http://stackoverflow.com/questions/10827894/how-do-i-slice-an-array-from-an-array-of-object-literals –