簡體   English   中英

如何從jQuery中的對象數組中刪除一個對象?

[英]How to remove an object from an array of objects in jquery?

我有以下代碼:

var pinpoints= [ { "top": 50,
                           "left": 161,
                           "width": 52,
                           "height": 37,
                           "text": "Spot 1",
                           "id": "e69213d0-2eef-40fa-a04b-0ed998f9f1f5",
                           "editable": true },
                         { "top": 0,
                           "left": 179,
                           "width": 68,
                           "height": 74,
                           "text": "Spot 2",
                           "id": "e7f44ac5-bcf2-412d-b440-6dbb8b19ffbe",
                           "editable": true } ] 

我如何能夠在pinpoints下從數組中刪除一些對象。

您可以使用pop()刪除數組的最后一個元素,也可以使用splice()方法刪除特定的元素。

例如,

pinpoints.splice(1, 1);   // removes element with index 1

pinpoints.splice(3, 10);  // removes ten elements, starting at index 3.

grep也應該為您工作

http://api.jquery.com/jQuery.grep

您可以使用jQuery filter()方法刪除元素。 它以選擇器或函數作為輸入。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM