数组的引用类型

作者: 小雪洁 | 来源:发表于2020-03-16 14:23 被阅读0次
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title>数组引用类型</title>
        </head>
        <body>
            <script>
                /* const array =[1,2,3,4,5];
                console.log(array);
                const a=array;//数组的复制是copy的地址
                a[2]="hxj";//所以改就是同一处改
                console.log(a);
                console.log(array);
                let b=2;
                let c=b;
                c=3;
                console.log(b);//还是2
                console.table(a); */
                
                //创建数组
                let cms=new Array(1,2,3,4);
                console.log(cms);//[1,2,3,4];
                let md =new Array(6);//创建6个空元素的数组
                console.log(md.length);//6
                console.log(md[3]);//undefined
                //新版js中
                let m= Array.of(6);//创建一个数组,只有一个元素,元素值是6,
                console.log(m.length);//1
                console.log(m);//[6]
                console.log(Array.of(1,2,3));//[1,2,3]
            </script>
        </body>
    </html>
    
    

    相关文章

      网友评论

        本文标题:数组的引用类型

        本文链接:https://www.haomeiwen.com/subject/voygehtx.html