HubSpot / youmightnotneedjquery

Home Page:http://YouMightNotNeedjQuery.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Spread operator is not needed for the iterable in for...of

ianthedev opened this issue · comments

The proposed vanilla version of remove is using the spread operator on the iterable in for...of:

el.remove();

// multiple elements
for (const el of [...document.querySelectorAll(selector)]) {
  el.remove();
}

The spread operator is actually not needed. The for...of loop can be simplified as:

for (const el of document.querySelectorAll(selector)) {
  el.remove();
}