I have JSON Object that looks something like the below object, this object can go on for days. So I am wondering is there anyway I can delete full set a set being the equiva
You could write a removeFirst function like this:
function removeFirst(arr, func)
{
for (var i=0; i
and then call it:
removeFirst(locations, function(){return this.zipcode=="06238";});
If you want to remove more then one element, you could write it like this:
function removeMany(arr, func)
{
for (var i=arr.length; i>0; --i)
{
if (func.call(arr[i]))
{
arr.splice(i,1);
}
}
return arr;
}
and use it in the same way.
Alternatively, use underscore (http://documentcloud.github.com/underscore) reject method in a similar way:
_.reject(locations, function(location){ return location.zipcode=="06238";});
Underscore is pretty good for doing array manipulations.