Answers for "js sort string array"

6

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é']
Posted by: Guest on May-01-2020
6

array sort by alphabetical javascript

users.sort((a, b) => a.firstname.localeCompare(b.firstname))
Posted by: Guest on August-29-2020
3

js sort string array

users.sort((a, b) => a.firstname.localeCompare(b.firstname))
Posted by: Guest on October-19-2020
1

javascript string array sort alphabetically

var items = ['réservé', 'premier', 'communiqué', 'café', 'adieu', 'éclair'];
items.sort((a, b) =>
   a.localeCompare(b)//using String.prototype.localCompare()
);
Posted by: Guest on August-12-2020
2

javascript sort array strings alphabetically

//sort array alphabetically
objArray.sort(function(a, b) {
   return a.localeCompare(b);
});
Posted by: Guest on September-23-2020
1

js order string

// function that returns a string in alphabetical order
function reorderStr(str) {
	return [...str].sort().join('');
}
console.log(reorderStr("hacker"));	//"acehkr"
console.log(reorderStr("javascript"));//"aacijprstv"
Posted by: Guest on March-12-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language