2016-03-07

JavaScript Array–find, add, remove

Note to myself.
Find index of an element:
var array = [2, 5, 9];
var index = array.indexOf(5);
Remove element based on index:
if (index > -1) {
    array.splice(index, 1);
}
Add element to array:
array.push(5);

No comments:

Post a Comment