As I think, JS array is just a hash-map which accepts only integral value as a key. And the .length property just return largest index + 1.
Is this right? Is there any other differences?
In JavaScript, arrays use numbered indexes. In JavaScript, objects use named indexes.
The length property of an Array object represents the number of elements in that array. The value is an unsigned, 32-bit integer that is always numerically greater than the highest index in the array.
The length property sets or returns the number of elements in an array.
{} is shorthand for creating an empty object. You can consider this as the base for other object types. Object provides the last link in the prototype chain that can be used by all other objects, such as an Array . [] is shorthand for creating an empty array.
You are wrong; arrays can have any keys you want.
Also, they inherit the Array
prototype.
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