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>
打印结果
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>
打印看到的结果是一致的
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>
打印结果
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>
打印结果