JavaScript 2025 · Strings

Sort text correctly

Sort strings using the language's rules, including accents and capitals.

names.sort((a, b) => a.localeCompare(b));

Official JavaScript 2025 documentation

More strings commands

All strings commands · JavaScript 2025 cheatsheet

Was this page helpful?