Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript splice

const arrayToBeFixed = ['a', 'b', 'wrong', 'f']

const removedElements = arrayToBeFixed.splice(2, // Where to insert
1, // number of elements to be removed from arrayToBeFixed
'c', 'd', 'e', // elements to add starting from the insertion index 
);

console.log(arrayToBeFixed) // ['a' 'b', 'c', 'd', 'e', 'f']
console.log(removedElements) // ['wrong']
Source by www.freecodecamp.org #
 
PREVIOUS NEXT
Tagged: #javascript #splice
ADD COMMENT
Topic
Name
6+2 =