1const months = ['Jan', 'March', 'April', 'June'];
2months.splice(1, 0, 'Feb');
3// inserts at index 1
4console.log(months);
5// expected output: Array ["Jan", "Feb", "March", "April", "June"]
6
7months.splice(4, 1, 'May');
8// replaces 1 element at index 4
9console.log(months);
10// expected output: Array ["Jan", "Feb", "March", "April", "May"]
11
12months.splice(0, 1);
13// removes 1 element at index 0
14console.log(months);
15// expected output: Array ["Feb", "March", "April", "May"]
1var arr = ["orange", "mango", "banana", "sugar", "tea"];
2var removed = arr.splice(2, 0, "water");
3console.log(arr); // orange,mango,water,banana,sugar,tea
4console.log(removed); // banana
1var arr = ["orange", "mango", "banana", "sugar", "tea"];
2var removed = arr.splice(2, 0, "water");
3console.log("After adding 1: " + arr );
4console.log("removed is: " + removed);
5
6removed = arr.splice(3, 1);
7console.log("After removing 1: " + arr );
8console.log("removed is: " + removed);