sort alphabetically javascript array code example
Example 1: js order alphabetically
const ascending = data.sort((a, b) => a[field].localeCompare(b[field]))
const descending = ascending.reverse()
Example 2: javascript return string in alphabetical order
function alphabet_Soup(str) {
return str.split("").sort().join("");
}
console.log(alphabet_Soup("Python"));
console.log(alphabet_Soup("Exercises"));
function alphaOrder(str) {
return str.split("").sort().join("");
}
console.log(alphaOrder("webdev"))
Example 3: javascript sort array in ascending order
function myFunction() {
points.sort(function(a, b){return a-b});
document.getElementById("demo").innerHTML = points;
}