Javascript: Remove an item from an array
I need to remove a specific item from a Javascript array. I'm sure there are lot of ways to do it, but this is a quicky function I came up with to do it.
// Loop through an array removing any matching items
function remove_item_from_array(needle, haystack) {
var ret = [];
for (i in haystack) {
var item = haystack[i];
if (item !== needle) {
ret.push(item);
}
}
return ret;
}