LoginSignup
0
0

More than 3 years have passed since last update.

javascript 配列の先頭や最後を削除したり配列に値を追加する

Posted at

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>課題</title>
    <script>
        var data = [59, 39, 100, 2, 15, 40, 84, 97];

        // 配列dataの先頭(59)の値を削除

        data.shift();

        // 配列dataの最後(97)の値を削除
        data.pop();

        // for文により配列dataの中身を表示
        for(var i = 0; i < data.length; i++){
            document.write('<p>'+data[i]+'</p>');
        }

    </script>
</head>
<body>
</body>
</html>




<!DOCTYPE html>
<html lang="ja">
<head>
   <meta charset="UTF-8">
   <title>challenge_object</title>
</head>
<body>
   <script>
       var fruits = new Array();

       fruits[0] = 'apple';
       fruits[1] = 'grape';
       fruits[2] = 'melon';

       // pushメソッドにより配列fruitsへorangeを追加
       fruits.push('orange')

       // for文により配列fruitsの中身を表示
       for(var i = 0; i < fruits.length; i++){
           document.write('<p>'+fruits[i]+'</p>')
       }


   </script>
</body>
</html>

0
0
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
0
0