我有一个空的下拉列表和一个数组但是我想按字母顺序在我的下拉列表中显示我的数组。我怎样才能实现这一目标?
<select id="dropdown">
</select>
var array = ["vintage","frames","treats","engraved", "stickers", "jewelerybox", "flask"];
答案 0 :(得分:0)
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"]