JavaScript Sort Array by Length Demo

This demo orders array elements by string length. A secondary alphabetical comparison makes equal-length results deterministic for the demo.

JavaScript Used in This Demo Top ↑

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




Subscribe to our YouTube Channel here



plus2net.com










✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer