To sort a string array in JavaScript in dictionary order, you can use the `sort()` method. To sort in descending order, you can use a custom compare function or reverse the array after sorting.
In this example,
const words = ["banana", "apple", "orange", "grape"];
words.sort();
console.log("Sorted Array Ascending:", words);
Sorted Array Ascending: [ 'apple', 'banana', 'grape', 'orange' ]
In this example,
const words = ["banana", "apple", "orange", "grape"];
words.sort((a, b) => b.localeCompare(a));
console.log("Sorted Array Descending:", words);
Sorted Array Descending: [ 'orange', 'grape', 'banana', 'apple' ]
In this tutorial, we learned How to Sort a String Array in Dictionary Order in JavaScript language with well detailed examples.