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 array with the .splice()
method.
--Karl
____________
Karl Swedberg
www.englishrules.com
www.learningjquery.com
On Apr 27, 2009, at 10: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 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