lengthproperty is automatically updated as new elements are added to the list.
lengthto a smaller value truncates the array.
Arrays inherit useful methods from
Arrays have a class attribute of “Array”.
regular objects. But they are not the essential features that define
an array. It is often perfectly reasonable to treat any object with a
length property and
corresponding non-negative integer properties as a kind of
These “array-like” objects actually do occasionally appear in
practice, and although you cannot directly invoke array methods on
them or expect special behavior from the
length property, you can still iterate
through them with the same code you’d use for a true array. It turns
out that many array algorithms work just as well with array-like
objects as they do with real arrays. This is especially true if your
algorithms treat the array as read-only or if they at least leave the
array length unchanged.
The following code takes a regular object, adds properties to make it an array-like object, and then iterates through the “elements” of the resulting pseudo-array:
// Start with a regular empty object
// Add properties to make it "array-like"
// Now iterate through it as if it were a real ...