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"]
1const apps = [
2 {id:1, name:'Jon'},
3 {id:2, name:'Dave'},
4 {id:3, name:'Joe'}
5]
6
7//remove item with id=2
8const itemToBeRemoved = {id:2, name:'Dave'}
9
10apps.splice(apps.findIndex(a => a.id === itemToBeRemoved.id) , 1)
11
12//print result
13console.log(apps)
1const array = [1, 2, 3];
2const index = array.indexOf(2);
3if (index > -1) {
4 array.splice(index, 1);
5}
1let items = ['a', 'b', 'c', 'd'];
2let index = items.indexOf('a')
3let numberOfElementToRemove = 1;
4if (index !== -1) { items.splice(index,numberOfElementToRemove)}
5
1var arr = [{id:1,name:'serdar'}, {id:2,name:'alfalfa'},{id:3,name:'joe'}];
2removeByAttr(arr, 'id', 1);
3// [{id:2,name:'alfalfa'}, {id:3,name:'joe'}]
4
5removeByAttr(arr, 'name', 'joe');
6// [{id:2,name:'alfalfa'}]
7