DEV Community

Discussion on: Find and Replace elements in Array with JavaScript

Collapse
 
ahirrea profile image
Ahirrea

Array.prototype.splice is really cool. I think it's worth to mention that you actually can do a replace with a third argument:

const arr = [1,2,3,4,5];
arr.splice(1, 1, 0);
arr;
// [1,0,3,4,5]