Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript splice

/*splice(start)
splice(start, deleteCount)
splice(start, deleteCount, replaceitem1)
splice(start, deleteCount, replaceitem1, ""2, ""N) */


//examples
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: #javascript #splice
ADD COMMENT
Topic
Name
1+2 =