JavaScriptで配列の要素を昇順に並び替える方法です
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>配列の並び替え</title>
</head>
<body>
<script>
const array1 = ["kosaka","kageyama","kato"];
// 配列を辞書順に並べる
array1.sort();
const num = array1.length;
for(let i=0;i<num;i++){
document.write(`<p>${array1[i]}</p>`);
}
</script>
</body>
</html>
sort関数を使います
const array1 = ["kosaka","kageyama","kato"];
// 配列を辞書順に並べる
array1.sort();
const num = array1.length;
for(let i=0;i<num;i++){
document.write(`<p>${array1[i]}</p>`);
}