开发者

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

I have this code:

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-b44开发者_运维知识库0-6dbb8b19ffbe",
                           "editable": true } ] 

How would I be able to remove some an object from the array under pinpoints.


You can use pop() to remove the last element of the array, or you can use the splice() method to remove a specific element.

For example,

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

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


grep should work for you too

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


You can use the jQuery filter() method to remove elements. It takes a selector, or a function as input.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜