In (almost 🙂 a one-liner
["Foo", "bar"].sort(function (a, b) {
return a.toLowerCase().localeCompare(b.toLowerCase());
});
Which results in
[ 'bar', 'Foo' ]
While
["Foo", "bar"].sort();
results in
[ 'Foo', 'bar' ]
More Related Contents:
- consider a string which has question marks, numbers , letters [closed]
- Sorting object property by values
- Javascript : natural sort of alphanumerical strings
- Is it correct to use JavaScript Array.sort() method for shuffling?
- Javascript Array.sort implementation?
- How to compare software version number using js? (only number)
- Sort mixed alpha/numeric array
- Sorting arrays numerically by object property value
- How to sort numbers correctly with Array.sort()? [duplicate]
- How do I sort an array of objects based on the ordering of another array?
- Sort Array by ISO 8601 date
- How can you sort an array without mutating the original array?
- Case insensitive string replacement in JavaScript?
- Count unique elements in array without sorting
- Javascript – Sort Array of objects by 2 Properties
- javascript sort of HTML elements
- Sorting Array with JavaScript reduce function
- Sorting an Array of Objects by two Properties
- Remove duplicate objects from an array using javascript
- Javascript – sorting array by multiple criteria
- 400x Sorting Speedup by Switching a.localeCompare(b) to (ab?1:0))
- Disable sorting for a particular column in jQuery DataTables
- How to prevent automatic sort of Object numeric property?
- Sort a Javascript Array by frequency and then filter repeats
- Sort a dictionary by value in JavaScript
- How to sort numbers? [duplicate]
- sorting object Sunday to Saturday in javascript
- Why doesn’t the sort function of javascript work well?
- How does one sort a multi dimensional array by multiple columns in JavaScript?
- javascript sort with unicode