java String.formate佔位符%d,%s等的使用
阿新 • • 發佈:2020-12-25
技術標籤:jssonsole.log()
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>
列印結果