Web App Development

Why does the object returned by jQuery() show up like an array in the console?

In Javascript an object with a length property and a splice function is an array-like object. Chrome and Firebug display these like arrays:

a = {length: 1, splice: function(){}, 0:"some value"}
>> ["some value"]
$(".tagged span").slice(0,2) // on Stackoverflow
>> [<span class=​"item-multiplier">​…​</span>​, <span class=​"item-multiplier-x">​×​</span>​]

The arguments variable is a special case because it is an array-like object even though it does not have a splice function.

Comments


Follow me on Twitter
I'm building monitoring tool for site speed and Core Web Vitals.
➔ Start monitoring your website or run a free site speed test