I have a empty dropdown list and a array however i want to display my array in my dropdown list in alphabetic order. How can i achieve this ?
<select id="dropdown">
</select>
var array = ["vintage","frames","treats","engraved", "stickers", "jewelerybox", "flask"];
var array = ["vintage","frames","treats","engraved", "stickers", "jewelerybox", "flask"];
array.sort(function(val1 , val2){
return val1.localeCompare(val2);
});
console.log(array); // ["engraved", "flask", "frames", "jewelerybox", "stickers", "treats", "vintage"]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.