Possible Duplicate:
Delete an array key when it contains a string in javascript
by using jquery, underscore or native javaScript I would like to delete or add element to an array.
here is my code;
var a = ['4', '5'];
var remove = false/true;
if(!remove) {
a.push('6'); // it works
} else {
a.remove(5); // I have no idea how to perform this in a very dry way
}
If you combine NULL and dystroy’s answer you can get Niko’s answer(ish) in pure js:
Or if you wanted to remove multiple ‘5’s
A neater method, that is rather unoptimal, only modern-browser supported (and also creates a new array) – but is still valid and more flexible is: