← TechnologyThe essentials of

toSorted(): a sorted copy that preserves the original order

Publisher: ResumeMaker • 1 source

Published: 22 Oct 2026 13:13 · Updated: 22 Oct 2026 13:13

AI source check: 21 Oct 2026 12:40. This is not editorial approval.

In a few sentences

In brief

The method is appropriate when the original arrangement is still needed.

Useful to know

toSorted() returns a new sorted array instead of rearranging the original one. For example, [12, 3, 8].toSorted((a, b) => a - b) gives [3, 8, 12]. The numerical comparison function is an essential . [1]

This helps with the "By price" interface, when you need to keep the order of receipt as well. The copy is shallow: an edit of an object property can be seen through both arrays. Check support in the target environment before using the method in an application for older browsers.

Sources

For further detail and to check the information:

  1. [1] MDN — Array.toSorted ↗