splice element from array javascript code example
Example 1: how to take an element out of an array in javascript
var data = [1, 2, 3];
data = data.splice(1, 1);
data = data.pop();
Example 2: add elements to middle of array using splice
const strings=['a','b','c','d']
strings.splice(2,0,'alien')
console.log(strings)
Example 3: splice javascritp
let colors = ['red', 'blue', 'green'];
let index_element_to_be_delete = colors.indexOf('green');
colors.splice(index_element_to_be_delete);
Example 4: array.splice javascript
const months = ['Jan', 'March', 'April', 'June'];
months.splice(1, 0, 'Feb');
console.log(months);
months.splice(4, 1, 'May');
console.log(months);
months.splice(0, 1);
console.log(months);
Example 5: Array#splice
let arrDeletedItems = array.splice(start[, deleteCount[, item1[, item2[, ...]]]])
Example 6: splice from array
let myFish = ['angel', 'clown', 'mandarin', 'sturgeon']
let removed = myFish.splice(2, 0, 'drum')