How to sort an object in Javascript using non-ASCII characters

Javascript Aug 11, 2021

This is a problem primarily at Brazil and countries that need to work with language with special characters such as: á, é, í.

Fortunately, Javascript to offer a simple way to resolve the problem:

let items = ['réservé', 'premier', 'communiqué', 'café', 'adieu', 'éclair'];

items.sort(function (a, b) {
  return a.localeCompare(b);
});

Reference: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort