2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

配列の並び替え(昇順)(JavaScript)

Last updated at Posted at 2023-01-01

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>`);
    }  
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?