On the current Google Chrome (Version 22.0.1229.79, on an iMac with Mountain Lion), the following code
var arr = [1, 3, 5];
console.log(arr);
delete arr[1];
console.log(arr);
console.log(arr.pop());
console.log(arr);
will show
[1, undefined × 2]
[1, undefined × 2]
5
[1, undefined × 1]
there are also other situation that caused Firefox to behave similarly as well. Are they bugs on Chrome and Firefox -- but it would seem strange that both Firefox and Chrome are susceptible to similar bugs -- or is it some behavior with array delete and console.log
? Supposedly, console.log
should not be running on a separate thread.
In Firefox 7.0:
var arr = [1,3,5];
console.log(delete arr[1]); // will show [1, undefined, 5]
And in my opinion it's a correct behavior =) So may be it's just a bug.
It is due to queued up console.log
processing, so the printing is delayed, and it shows a later version of the object or array: Is Chrome's JavaScript console lazy about evaluating arrays?
My answer there has 5 solutions and JSON.stringify()
was the best one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With