Get started with natsort CDN
MIT licensed
Libraries like natsort sort arrays naturally, converting strings to numbers if feasible.
Tags:- natural
- natsort
- sort
- sorter
- numeric
- unicode
- algorithm
- date
- datetime
- desc
- case-insensitive
Stable version
Copied!
How to start using natsort CDN
// Include the natsort library
const script = document.createElement('script');
script.src = "https://cdn.cdnhub.io/natsort/2.0.3/natsort.min.js";
document.head.appendChild(script);
// Wait for the library to be loaded
window.addEventListener('load', () => {
// Assume we have an array of strings called 'arr' that we want to sort
const arr = ['zebra', 'apple', 'banana', 'kiwi', 'orange'];
// Use natsort to sort the array
const sortedArr = arr.slice().sort((a, b) => NatSort(a, b));
console.log(sortedArr); // Output: ["apple", "banana", "kiwi", "orange", "zebra"]
});
Copied!