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];
1const array = [1, 2, 3];
2const index = array.indexOf(2);
3if (index > -1) {
4 array.splice(index, 1);
5}
1let numbers = [1,2,3,4]
2
3// to remove last element
4let last_num = numbers.pop();
5// numbers will now be [1,2,3]
6
7// to remove first element
8let first_num = numbers.shift();
9//numbers will now be [2,3]
10
11// to remove at an index
12let number_index = 1
13let index_num = numbers.splice(number_index,1); //removes 1 element at index 1
14//numbers will now be [2]
15
16//these methods will modify the numbers array and return the removed element