Convert List like into List
The error document.querySelectorAll(...).map is not a function
occurs because querySelectorAll
returns a NodeList
, which is not an Array and does not have the map
method. To solve this, you can convert the NodeList
to an Array using one of the following methods:
- Spread Operator
- Array.from()
- Array.prototype.slice.call()
After converting the NodeList
to an Array, you can then use the map
method to get the innerText
of each element.
Here’s an example using the spread operator:
This will give you an array of the text content of each element with the class dir-item
.