Skip to content
UniCircle
MediumConceptualArrays

Array-like objects

Question JS-ARR-004

What is an array-like object? Give two examples you meet in real code, and show how to turn one into a real array.

Show the explanation

Model answer. An array-like object has numbered keys and a length property, but is not an Array, so it lacks methods like map and filter.

Common examples:

  • arguments inside a non-arrow function
  • a DOM NodeList from querySelectorAll (modern ones do have forEach, but not map)
  • an HTMLCollection from getElementsByClassName
  • strings (indexed characters with a length)

Converting:

JavaScript
const items = document.querySelectorAll('li');
const arr1 = Array.from(items);            // works for array-likes and iterables
const arr2 = [...items];                   // works for iterables only
const texts = Array.from(items, li => li.textContent);  // convert + map in one step

Array.from is the safest choice because it accepts plain { length, 0:..., 1:... } objects too, which spread does not (they are not iterable).

Original UniCircle question. Last reviewed 22 Oct 2026.