2020-12-24 柔光的暖阳◎ 2021-07-24 17:07 227阅读 0赞 console.log(),对于一般对于基本类型number、string、boolean、null、undefined 的输出是可信的。但对于Object 等引用类型来说,则就会出现上述异常打印输出。(调试复杂数据类型时候通过打断点来看即可) 正常预期 <script> var arr1 = [1,2] // let arr1 = [ // {id:1,name:1}, // {id:2,name:2} // ] console.log(arr1); arr1[0]=111111; console.log(arr1); </script> 打印结果 ![在这里插入图片描述][2020122418150511.png] 1.直接打印前后数组的值 和预期结果一样 <script> // var arr1 = [1,2] let arr1 = [ { id:1,name:1}, { id:2,name:2} ] console.log(arr1); arr1[0]=111111; console.log(arr1); </script> 打印看到的结果是一致的 ![在这里插入图片描述][2020122418120943.png] 2.打印到具体的看却不一致 和预期一样 <script> // var arr1 = [1,2] let arr1 = [ { id:1,name:1}, { id:2,name:2} ] console.log(arr1[0]); arr1[0]=111111; console.log(arr1[0]); </script> 打印结果 ![在这里插入图片描述][20201224181118879.png] 3.做判断 也是不一致 和预期一样 <script> // var arr1 = [1,2] let arr1 = [ { id:1,name:1}, { id:2,name:2} ] if (arr1[0] > 1) { console.log(1,arr1); }else { console.log(2,arr1); } arr1[0]=111111; // console.log(arr1); if (arr1[0] > 1) { console.log(3,arr1); }else { console.log(4,arr1); } </script> 打印结果 ![在这里插入图片描述][20201224180941781.png] [2020122418150511.png]: /images/20210724/27aa57e943b54cdc937cd6c62bc51af8.png [2020122418120943.png]: /images/20210724/53017e58c8c8438e8a5ca00e25fd29e4.png [20201224181118879.png]: /images/20210724/250c44afda9440608a60354b54be4086.png [20201224180941781.png]: /images/20210724/ecef0f3043de428389875ade2759d7e3.png
还没有评论,来说两句吧...