What is JavaScript array.splice()?
👨🏻‍💻

What is JavaScript array.splice()?

Created
Apr 27, 2021 09:11 AM
Tags
5 Mins read
JavaScript
Web Dev
Programming
Description
A brief explanation of what is array.splice().
Updated
Last updated April 28, 2021

So what is array.splice()?

ArrayName.splice(start, how_many_items_to_remove, item1, item2, ...);
  • The first parameter 'start' is the index to start.
  • The second parameter 'how_many_items_to_remove' it's how many items to be removed from an array.
  • The third parameter is what values to add to the array.

For Example:

let cars = ['Volvo','BMW','Toyota', 'Audi']; let result = cars.splice(2,1,'Mercedes'); console.log(result); // ['Volvo', 'BMW', 'Mercedes', 'Audi']

More in this series: