JavaScript Code

How to sort array of strings lexicographically?

Problem Statement

given an array of strings, write a JavaScript program to sort the array in ascending order lexicographically (order of english dictionary)


to sort an array of strings in ascending order, use array sort() method. sort() method sorts the array of strings lexicographically in ascending order, by default


fruits is the given array of strings. we use array sort() to sort strings lexicographically in ascending order

let fruits = ['cherry', 'apple', 'banana'];

copyright @2022