GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

Conversation

@AlexNT-maker

@AlexNT-maker 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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@AlexNT-maker
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 javascript-translate-bot added the review needed Review needed, please approve or request changes label May 21, 2026
@javascript-translate-bot
javascript-translate-bot requested review from a team May 21, 2026 13:18
@CLAassistant

CLAassistant commented May 21, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

AKzar1el
AKzar1el reviewed Nov 3, 2026
View reviewed changes

@AKzar1el AKzar1el left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
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.

@AKzar1el AKzar1el Nov 3, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The claim that toSorted() is “more optimized” than copying and sorting isn't guaranteed. MDN describes it as the copying version of sort(), whose complexity depends on the implementation; readers may mistake this for a performance guarantee over [...arr].sort(). Could we remove the performance claim and keep the clear non-mutating behavior explanation?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@AlexNT-maker AlexNT-maker Nov 3, 2026

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Done! Thanks for the review! I have removed the performance claim in the latest commit.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@AlexNT-maker
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

Reviewers

1 more reviewer
@AKzar1el AKzar1el AKzar1el left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

review needed Review needed, please approve or request changes

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@AlexNT-maker @CLAassistant @AKzar1el @javascript-translate-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.