A very simple code to illustrate the difference.
var x = [0, 3, 1, 2];
console.debug('debug', x);
console.log('log', x);
// above display the same result
x.splice(1, 2);
// below display kind of a different result
console.debug('debug', x);
console.log('log', x);
alt text http://sixbytesunder.com/stuff/firebug_console.png
The javascript value is exactly the same but console.log() displays it a bit differently than before applying splice() method. Because of this I lost quite a few hours as I thought splice is acting funny making my array multidimensional or something.
I just want to know why does this work like that. Does anyone know? 🙂
If you look at the documentation, it says:
A look on that page shows at
console.log:So, I think that before the
splice, the array is internally still an Array (I know, it is a kind of object), but after the operation, you get a general object, at least internally. I know this is a weak explanation, but Firebug has more strange behaviour in the console.BTW, the ECMAScript specification says nothing useful, but we can read in the section about
Array.prototype.splice(§ 15.4.4.12):