Back

TIL in JavaScript, the reverse() method mutates the array and just returns a reference to the same array. I wrongly assumed it would return a new array and leave the original array untouched 😬

1 • •

107

•
  • No matching results...
  • Searching...

/ 1000

That was the reason behind the addition of the toReversed developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toReversed

and other non-mutating array functions. Been burned by this many times... there is a polyfill for it but also some implementations that are worth having in your tool belt

• •

88

•