Similarities with arrays in JavaScript

Let's see how pseudo-arrays are similar to regular arrays.

Indices

The elements of a pseudo-array, like the elements of a regular array, can be accessed by their index:

javascriptconsole.log(elems[0]);
console.log(elems[1]);
console.log(elems[2]);

Length

You can also find out the number of elements using the length property:

javascriptconsole.log(elems.length);

Loop

It is possible to loop through the elements of a pseudo-array:

javascriptfor (let elem of elems) {
  console.log(elem);
}

Practical tasks

Задание 1

Paragraphs are given:

javascriptlet elems = document.querySelectorAll('p');

Check for the variable elems the described possibilities of pseudo-arrays.