国产av日韩一区二区三区精品,成人性爱视频在线观看,国产,欧美,日韩,一区,www.成色av久久成人,2222eeee成人天堂

Creation and manipulation of arrays in JavaScript

How to create an array


##1. Use the new keyword and Array() to create an array
##var arr = new Array(); //Create an empty array

var arr = new Array("zhou gensheng" , "male" , 30); //Create an array and initialize the elements of the array

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php.cn</title>
        <script>           
            //創(chuàng)建一個沒有任何元素的數(shù)組
            var arr = new Array();
            //增加數(shù)組元素
            arr[0] = "張三";          
            arr[1] = "男";          
            arr[2] = 25;          
            arr[3] = "安徽";          
            document.write(arr);         
        </script>
    </head>
    <body>
    </body>
</html>



2. Use [] to create

## square brackets [ ], use commas in English to separate multiple values.

The value of the array element can be of any type. Such as: character type, numeric type, Boolean type, array type, object type, function.

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php.cn</title>
        <script>          
            //使用[]方式創(chuàng)建一個數(shù)組
            var arr = ["張三","男",25,"安徽"];         
            document.write(arr);         
        </script>
    </head>
    <body>
    </body>
</html>


Array operations


Read elements: Read elements that already have subscripts. For example: var age = arr[2];
  • Modify element: Modify the value of an element with an existing subscript (reassign a value). For example: arr[2] = 26;
  • Add element: add an element with a non-existent subscript.
  • Delete elements: Using the keyword delete, you can only delete the value of the element, while the subscript is still there.


Continuing Learning
||
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> //使用[]方式創(chuàng)建一個數(shù)組 var arr = new Array("張三","男",25,"安徽"); document.write(arr); </script> </head> <body> </body> </html>
submitReset Code