← Winnitude! Search  ·  Reader Mode (1235 ms)
Links: Stay in Reader Retro Site Converter Retro Mode: OFF Original Page ↗
GITHUB · 29 LINKS

feat: add toSorted() explanation and examples. by AlexNT-maker · Pull Request #3963 · javascript-tutorial/en.javascript.info

Repository navigation

feat: add toSorted() explanation and examples. - #3963


Open
AlexNT-maker wants to merge 2 commits into javascript-tutorial:master from AlexNT-maker:patch-1
Open

feat: add toSorted() explanation and examples. #3963 AlexNT-maker wants to merge 2 commits into javascript-tutorial:master from AlexNT-maker:patch-1

Conversation

AlexNT-maker commented May 21, 2026



Copy link Copy Markdown
  • Briefly explains the concept of immutability and why mutating original data is avoided in modern JS.
  • Introduce toSorted() as the modern alternative to sort() .
  • Includes a runnable code block (js run) demonstrating how the original array remains untouched compared to the new sorted array.
feat: add toSorted() explanation and examples. 0d889a4
- Briefly explains the concept of immutability and why mutating original data is avoided in modern JS.
- Introduce` toSorted()` as the modern alternative to `sort()` .
- Includes a runnable code block (`js run`) demonstrating how the original array remains untouched compared to the new sorted array.
javascript-translate-bot added the review needed Review needed, please approve or request changes label May 21, 2026 javascript-translate-bot requested review from a team May 21, 2026 13:18

CLAassistant commented May 21, 2026 · edited Loading



Copy link Copy Markdown


All committers have signed the CLA.

AKzar1el reviewed Nov 3, 2026
View reviewed changes

AKzar1el left a comment



Copy link Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more .

One accuracy issue in the new explanation, noted inline.

Comment thread 1-js/05-data-types/05-array-methods/article.md
Outdated

### toSorted

In modern JavaScript, we generally avoid mutating original data, as it can lead to unexpected side effects and bugs. Because the traditional `sort()` method modifies the array in place, a new modern method was introduced. The `toSorted()` method elegantly solves this problem by returning a completely new, sorted array, leaving the initial data safely intact. It is also more optimized than the older workaround of manually cloning the array before sorting.
Clarify toSorted method description 5e9a170
Removed mention of manual cloning in toSorted method explanation.
Sign up for free to join this conversation on GitHub . Already have an account? Sign in to comment

Labels

review needed Review needed, please approve or request changes

4 participants