define splice code example

Example 1: splice()

/"removes any number of consecutive elements from anywhere in an array."/
let array = ['today', 'was', 'not', 'so', 'great'];

array.splice(2, 2);
// remove 2 elements beginning with the 3rd element
// array now equals ['today', 'was', 'great']

Example 2: what is splice in javascript

let colors = ['red', 'blue', 'green'];

let index_element_to_be_delete = colors.indexOf('green');

colors.splice(index_element_to_be_delete); 

//Colors now: ['red', 'blue']

Example 3: splice

var fruits = ["Banana", "Orange", "Apple", "Mango"];

fruits.splice(2, 0, "Lemon", "Kiwi");