JavaScript array object property length and two-dimensional array

Array object attribute length

An array is actually an "array object". Thinking of an array as an "object" is to use the properties or methods of the array object.

In JS, all content is "object".

Then, length is a property of the array object. For example: var len = arrObj.length;

length attribute can dynamically obtain the length of the array.

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php.cn</title>
        <script>
            var arr = ["涛哥" , "男" , 24, "大专" , "北京科技大学" ];
                document.write(arr.length);
        </script>
    </head>
    <body>
    </body>
</html>


Two-dimensional array

Give an array element , assign the value of an array, then this array is a "two-dimensional array".

Create a simple two-dimensional array:

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php.cn</title>
        <script>          
            //使用[]方式创建一个数组
            var arr = [
                [1,2,3,4],
                [4,5,6,7],
                [8,9,10,11]
            ];         
            document.write(arr);        
        </script>
    </head>
    <body>
    </body>
</html>
  • A two-dimensional array must be implemented with two layers of loops. In other words, cycles within cycles.

  • Access to two-dimensional arrays: The array name is followed by multiple consecutive brackets []. The first bracket [] represents the first-dimensional array, and the second bracket [] Represents the second dimension array.

<!DOCTYPE HTML>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>php.cn</title>
        <script>          
            //使用[]方式创建一个数组
            var arr = [
                [1,2,3,4],
                [4,5,6,7],
                [8,9,10,11]
            ];         
            document.write(arr[1][1]);        
        </script>
    </head>
    <body>
    </body>
</html>


Continuing Learning
||
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>php.cn</title> <script> var arr = ["涛哥" , "男" , 24, "大专" , "北京科技大学" ]; document.write(arr.length); </script> </head> <body> </body> </html>
submitReset Code