It's not needed to convert to array in this example: [...$$("a[href *='#']")].forEach(console.log);
querySelectorAll returns NodeList. While that is not an array, it does have forEach natively. It would be more appropriate to use one of these:
- $$("a[href *='#']").forEach(console.log)
- [...$$("a[href *='#']")].map(element => console.log(element.href))
Maybe these things could be pointed out separately - what's NodeList, converting spreadables to arrays and also applying array methods to spreadable items directly. You know - [...$$('a')].map(myFun) creates an array while Array.prototype.map.call($$('a'), myFun) uses the map method on whatever.
[...$$("a[href *='#']")].forEach(console.log)
It's not needed to convert to array in this example:
[...$$("a[href *='#']")].forEach(console.log);querySelectorAllreturnsNodeList. While that is not an array, it does haveforEachnatively. It would be more appropriate to use one of these:Maybe these things could be pointed out separately - what's NodeList, converting spreadables to arrays and also applying array methods to spreadable items directly. You know -
[...$$('a')].map(myFun)creates an array whileArray.prototype.map.call($$('a'), myFun)uses the map method on whatever.[...$$("a[href *='#']")].forEach(console.log)