Just read these new array methods

4 new array methods:

  1. toReversed
  2. toSorted
  3. toSpliced
  4. with

Haven’t tried them yet but apparently the original array is not affected as with the methods reverse, sort and splice… I mean, wow!

2 Likes

I don’t think they are actually officially part of the language yet. At least my Chrome and Firefox don’t recognize them by default. But I think you can go into the settings and turn on a flag to get them to work. These methods are at the very end of the proposal process and should be official very soon. But of course it’s going to take a while for everyone out there to upgrade to a browser version that includes them. So in the foreseeable future you’ll have to include a polyfill/shim if you want to use them or use a transpiler to convert them to a form that older browsers can understand.

UPDATE: It looks like they will be unflagged in Chrome 110 and are currently unflagged in Safari. Not sure when Firefox will do the same?

tc39/proposal-change-array-by-copy

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.