gengns ES

An entry from the gengns log, written by Génesis García Morilla · · JavaScript

Sort an array of numeric, alphabetic and alphanumeric values

JavaScript

let array = ['a2', '22', 'a10', '10', 'a11', '1']

document.body.textContent = array.sort(Intl.Collator(0, {numeric: true}).compare)
Open in JSFiddle

Thanks to japanfever who basically reached this one line approach!

Tags: sort