I'm a full-stack Software Engineer and Architect. I specialise in front-end niceness, but my daily tasks are mostly about making server less work well and scale within our suit of micro services!
Not sure how spread makes it more clear?!?! Array.prototype.slice is literally intended and is know to make a copy of an array....
From MDN:
The slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.
Using the spread operator in no way marks an intent to copy. The only thing that says that in your code is the comment. 🤣
And if you understand splice, it modifies the array in place....
Not sure how spread makes it more clear?!?!
Array.prototype.slice
is literally intended and is know to make a copy of an array....From MDN:
Using the spread operator in no way marks an intent to copy. The only thing that says that in your code is the comment. 🤣
And if you understand splice, it modifies the array in place....
so, three operations:
COPY :
const _copy = x.slice()
DELETE:
_copy.splice(y, 1)
RETURN
It's pretty damn easy to understand. Wrap it in a function if you want
safelyDeleteFromArrayAtIndex(array, index)