Array Length returns 0

Only numeric indices affect the .length of an Array.

Other named properties are allowed, but they aren’t the typical use for an Array object. By using "", you’re creating a non-numeric property on the object. You can access it like this:

errors[""];

But you can’t get to it with the typical Array methods.


For named properties, you’d typically use an Object instead. Either way, you can get a count of the number of own, enumerable properties (including numeric indices) by using Object.keys().

Object.keys(errors).length;

Leave a Comment