Petr
Petr

Reputation: 2099

Typescript correct way to loop through elements

What is the best way to loop through elements like document.querySelectorAll('.calendar-table td .available') or className using Typescript?

I found many answers using Javascript but some of them with clearer code wasn't supported with all browsers (.forEach for examp but since Typescript compiles back to javascript, then there should be some nice solution working with all browsers? Thank you

Upvotes: 1

Views: 288

Answers (1)

basarat
basarat

Reputation: 275957

Just use Array.from e.g. const arr = Array.from(document.querySelectorAll('.calendar-table td .available')) and use your standard loops e.g. .forEach etc.

More

Upvotes: 1

Related Questions