Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

splice javascript list

The splice() method changes the contents of an array by removing or
replacing existing elements and/or adding new elements in place.

To access part of an array without modifying it, see slice().

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"]
Source by developer.mozilla.org #
 
PREVIOUS NEXT
Tagged: #splice #javascript #list
ADD COMMENT
Topic
Name
7+8 =