This turns it into a convenient function:
function remove_element(array, item) {
for (var i = 0; i < array.length; ++i) {
if (array[i] === item) {
array.splice(i, 1);
return;
}
}
}
var array = ["google", "chrome", "os", "windows", "os"];
remove_element(array, "chrome");
or (for browsers that support indexOf):
function remove_element(array, item) {
var index = array.indexOf(item);
if (-1 !== index) {
array.splice(index, 1);
}
}
: === !==.