Q:

What is the best way to add/remove an element from an array?

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
}

A:

If you combine NULL and dystroy's answer you can get Niko's answer(ish) in pure js:
a.splice(a.indexOf('5'),1);

Or if you wanted to remove multiple '5's
var p;
while( (p = a.indexOf('5')) != -1 ){
    a.splice(p, 1);
}

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:
a = a.filter(function(v){
  return v != '5';
});

