DEV Community

loading...

Discussion on: MODERN METHODS TO REMOVE ITEMS FROM ARRAYS IN JAVASCRIPT

Collapse
crazyoptimist profile image
CrazyOptimist

Nice post!
shift() mutates the original array, but it can be used for const.

const arr = [1, 2, 3];
arr.shift();
console.log(arr)
// output: [2, 3]
Enter fullscreen mode Exit fullscreen mode

How can we explain this? And is it a good practice to use const instead of let in such cases?
Please advice.