当前位置:网站首页>JS learning notes 14-15: JS array and array letter quantity

JS learning notes 14-15: JS array and array letter quantity

2022-07-19 08:30:00 The man fished alone in the cold river snow

<!DOCTYPE html>
<html lang="en">
<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>Document</title>
    <script>
        var arr=new Array();

        // Use typeof When checking an array , Returns the object
        // console.log(typeof arr);
         
        /*  For continuous arrays , Use length You can get the length of the array ( Number of elements )  For discontinuous arrays , Use length Will get the largest index of the array +1  modify length  If modified length Larger than the original length , Then the extra part will be empty   If modified length Less than the original length , The extra elements will be deleted  */
        arr[0]=10;
        arr[1]=33;
        console.log(arr.length);
        // When you create an array using literals , You can specify the elements in the array at creation time 
        var arr=[1,2,3,4,5,10];
        
        // When creating an array using a constructor , You can also add elements at the same time , The element to be added is passed as a parameter of the constructor  
        var arr2=new Array(10,20,30);

        //console.log(arr2.length);
        // The elements in the array can be any data type 
        arr=["hello",1,true,null,undefined];
        // It could be an object 
        arr[arr.length]=obj;
        var obj=[{
    name:" The Monkey King "},{
    name:" Pig eight quit "},{
    name:" The sand monk "}];
        // Add at the end of element obj // It can also be a function  arr=[function(){
    alert(1)},function(){
    alert(2)}];

        // You can also put an array in the array , The following array is called two-dimensional array 
        arr=[[1,2,3],[3,4,5],[5,6,7]];
        console.log(arr[1]);
        


        </script>
</head>
<body>
    
</body>
</html>
原网站

版权声明
本文为[The man fished alone in the cold river snow]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/200/202207170727469987.html