Skip to content

The array in querySelectorAll example is not necessary #22

Description

@tontonsb

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions