[jQuery] Re: Removing item from array based on property

2009-04-27 Thread Mervyn
Both methods worked perfectly. Thank you. On Apr 27, 12:21 pm, mkmanning wrote: > Not sure why $.grep didn't work for you. Here's a functioning sample > to compare: > > arr = $.grep(arr,function(n,i){ >         return n.a1 != 1; > > }) > > On Apr 27, 7:51 am, Mervyn wrote: > > > > > Hello all,

[jQuery] Re: Removing item from array based on property

2009-04-27 Thread mkmanning
Not sure why $.grep didn't work for you. Here's a functioning sample to compare: arr = $.grep(arr,function(n,i){ return n.a1 != 1; }) On Apr 27, 7:51 am, Mervyn wrote: > Hello all, > > I have a question about removing an item from an array. > > I am looking to remove an item from the ar

[jQuery] Re: Removing item from array based on property

2009-04-27 Thread Karl Swedberg
Hey Mervyn, this should do it: var arr = [{a1: 1, a2: 2},{a1: 3, a2: 4}, {a1: 5, a2: 6}]; for (var i=0; i < arr.length; i++) { if (arr[i].a1 == 1) { arr.splice(i,1); } } just loop through the members of the array and check each one's a1 property. If it equals 1, remove it from the