Let's have a pseudo-array of paragraphs:
let elems = document.querySelectorAll('p');
Let's convert it to a regular array.
The first way
The most obvious thing to do is to iterate over our pseudo-array in a loop, forming a new array in this loop:
let arr = [];
for (let elem of elems) {
arr.push(elem);
}
The second way
We can use destructuring:
let arr = [...elems];
The third way
We can use Array.from
method:
let arr = Array.from(elems);
Practical tasks
Somehow get a pseudo-array of elements. Convert it to an array in the three ways described.
Paragraphs are given:
let elems = document.querySelectorAll('p');
Use the slice
method to get
all the paragraphs except the first
and last.