Tuesday, 19 March 2019

Array.length vs arrayinstance.length in javascript

I'm a bit confused by the Array.length property (i.e. a property named length on the Array function object) and array_instance.length (i.e. a property named length on instance of array object)

enter image description here

So what is difference between the two length property and when should/shouldn't we use them?

Edit 1:

there is also a length property on Array.prototype object. I am so confused.

enter image description here

Edit 2

Just to paint a clearer picture, here are the different length properties I have found

enter image description here

Edit 3

This is one of the follow up questions I asked in the comment section, but I think the question is important to fully understanding length property, so I have copy-pasted here in the main section

Follow up question:

Array.prototype.hasOwnProperty('length') and Array_instance.hasOwnProperty('length') return true, does that mean there are two length properties, one on array_instance, one on Array.prototype object, with the array_instance.length overshadowning the Array.prototype.length?



from Array.length vs arrayinstance.length in javascript

No comments:

Post a Comment