86
rated 0 times
[
93]
[
7]
/ answers: 1 / hits: 52928
/ 11 Years ago, mon, june 17, 2013, 12:00:00
Here is my code for javascript for this simple task:
- Remove the element if it exists in an array.
Add the element if it is not in an array.
if(_.contains(this.types,type_id)){
var index = this.types.indexOf(type_id);
this.types.splice(index,1);
}
else{
this.types.push(type_id);
}
Is there a more efficient way to do this?
More From » arrays