0

Using JavaScript splice() method to change the content of an array by removing or replacing existing elements and/or adding new elements in place

JavaScript
const months = ['Jan', 'March', 'April', 'June'];
months.splice(1, 0, 'Feb');
// inserts at index 1
console.log(months); // ["Jan", "Feb", "March", "April", "June"]


months.splice(4, 1, 'May');
// replaces 1 element at index 4
console.log(months); // ["Jan", "Feb", "March", "April", "May"]

RUN
add comment
Suggest a different solution or add another example