This demo orders array elements by string length. A secondary alphabetical comparison makes equal-length results deterministic for the demo.
const values = ["PHP", "ASP", "JavaScript", "HTML"];
values.sort((a, b) => a.length - b.length || a.localeCompare(b));
console.log(values);
Array sort() Tutorial Alphabetical Demo Display Array Elements
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.