Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript sort alphabetically

var items = ['réservé', 'premier', 'communiqué', 'café', 'adieu', 'éclair'];
items.sort(function (a, b) {
  return a.localeCompare(b); //using String.prototype.localCompare()
});

// items is ['adieu', 'café', 'communiqué', 'éclair', 'premier', 'réservé']
 
PREVIOUS NEXT
Tagged: #javascript #sort #alphabetically
ADD COMMENT
Topic
Name
7+8 =