Reputation: 2099
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
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.
Upvotes: 1