Monday, April 27, 2009

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

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 <mervyn.mar...@gmail.com> wrote:
> Hello all,
>
> I have a question about removing an item from an array.
>
> I am looking to remove an item from the array based on the property.
>
> Ie.
> arr = [{a1: 1, a2: 2},{a1: 3, a2: 4}, {a1: 5, a2: 6}]
>
> remove first item from array because a1 = 1.
>
> I am not entirely sure how to do this. I tried messing around with
> grep a bit, but that didn't turn out well.
>
> Thanks

No comments: