1

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-b440-6dbb8b19ffbe",
                           "editable": true } ] 

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

anthonypliu
  • 11,779
  • 28
  • 88
  • 152

3 Answers3

5

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.
womp
  • 113,785
  • 25
  • 233
  • 264
2

grep should work for you too

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

PeterWong
  • 15,851
  • 9
  • 58
  • 67
0

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

g.d.d.c
  • 44,141
  • 8
  • 97
  • 109