我有以下對象:刪除項目對象的JavaScript
[{
"id": 2,
"price": 2000,
"name": "Mr Robot T1",
"image": "http://placehold.it/270x335"
}, {
"id": 1,
"price": 1000,
"name": "Mr Robot T2",
"image": "http://placehold.it/270x335"
}]
和我要的是刪除第一個項目(ID = 1),結果是:
[{
"id": 2,
"price": 2000,
"name": "Mr Robot T1",
"image": "http://placehold.it/270x335"
}]
,因爲它可以做?
轉到MDN並閱讀有關Array.prototype。不要跑到stackoverflow問這樣的基本問題。此外,這與jQuery沒有任何關係。 – Azamantes
你有一個對象數組,而不僅僅是一個對象。您要求刪除數組中的一個索引項目。參見:['Array.prototype.splice()'](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice) – Makyen
Bonsoir Elliot:'array.splice (0,1)' – jrbedard