1var colors = ["red","blue","car","green"];
2var carIndex = colors.indexOf("car");//get "car" index
3//remove car from the colors array
4colors.splice(carIndex, 1); // colors = ["red","blue","green"]
1var data = [1, 2, 3];
2
3// remove a specific value
4// splice(starting index, how many values to remove);
5data = data.splice(1, 1);
6// data = [1, 3];
7
8// remove last element
9data = data.pop();
10// data = [1, 2];
1var myArr = [{id:'a'},{id:'myid'},{id:'c'}];
2var index = arr.findIndex(function(o){
3 return o.id === 'myid';
4})
5if (index !== -1) myArr.splice(index, 1);
1var colors = ["red","blue","car","green"];
2var carIndex = colors.indexOf("car");//get "car" index
3//remove car from the colors array
4colors.splice(carIndex, 1); // colors = ["red","blue","green"]
1let value = 3
2
3let arr = [1, 2, 3, 4, 5, 3]
4
5arr = arr.filter(item => item !== value)
6
7console.log(arr)
8// [ 1, 2, 4, 5 ]
1var array = ['Object1', 'Object2'];
2
3// SIMPLE
4 array.pop(object); // REMOVES OBJECT FROM ARRAY (AT THE END)
5 // or
6 array.shift(object); // REMOVES OBJECT FROM ARRAY (AT THE START)
7
8// ADVANCED
9 array.splice(position, 1);
10 // REMOVES OBJECT FROM THE ARRAY (AT POSITION)
11
12 // Position values: 0=1st, 1=2nd, etc.
13 // The 1 says: "remove 1 object at position"