how to use splice without return an array in javascript code example
Example 1: array.splice javascript
const months = ['Jan', 'March', 'April', 'June'];
months.splice(1, 0, 'Feb');
// inserts at index 1
console.log(months);
// expected output: Array ["Jan", "Feb", "March", "April", "June"]
months.splice(4, 1, 'May');
// replaces 1 element at index 4
console.log(months);
// expected output: Array ["Jan", "Feb", "March", "April", "May"]
months.splice(0, 1);
// removes 1 element at index 0
console.log(months);
// expected output: Array ["Feb", "March", "April", "May"]
Example 2: javascript splice without changing array
var myArray = ["one", "two", "three"];
var cloneArray = myArray.slice();
myArray.splice(1, 1);
console.log(myArray);
console.log(cloneArray);