Open this example in the interactive library
Source code
const collator = new Intl.Collator("en", { numeric: true });
console.log(["file10", "file2", "file1"].sort(collator.compare));
Sample output
[ 'file1', 'file2', 'file10' ]

Compare human-readable numbers. A self-contained example using the JavaScript runtime.
Open this example in the interactive library
const collator = new Intl.Collator("en", { numeric: true });
console.log(["file10", "file2", "file1"].sort(collator.compare));
[ 'file1', 'file2', 'file10' ]