簡體   English   中英

在控制台中打印數組時長度錯誤

[英]Getting a wrong length when printing an array in console

在對數組進行console.log時,我得到以下結果:

25 != 2727 == 27

第一張圖片(頂部)中的數字(25)代表什么? 我的數組的長度為 27,而不是 25。我認為這是非null值的計數,但第二張圖片表明並非如此。

(25) 和 (27) 也以簡化形式存在:

25 != 2727 == 27

這發生在 Firefox 和 Chrome 中。

導致這種行為的代碼:

var lows = ts2values[current_ts];
var highs = ts2values[current_ts];

console.log("lows b : ", lows);
console.log("highs b : ", highs);

lows.push(null);
highs.push(null);

console.log("lows a : ", lows);
console.log("highs a : ", highs);

第一張圖片(頂部)中的數字(25)代表什么?

當時數組的長度。

您可以通過以下代碼看到相同的結果。

myArray = [1, 2, 3]
console.log(myArray)

myArray.push(4, 5, 6)
console.log(myArray)

第一個日志是Array(3)

控制台,不展開數組

並擴展第一個日志,數組的長度是6,而不是3,因為它是在console.log之后更新的

控制台,展開數組

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM