Re:Bootstrap 5 will remove jQuery as a dependency
by Carpetsmoker on Thursday February 14, 2019 @12:56AM
(#19159907)
I should have explained the use case better: I need to store an indexed array of elements for cache/querying later on; so forEach() isn't a good fit here.
Other people suggested Array.from(), but that won't work in IE, and the polyfill for it is a lot longer/more complex than the for loop I wrote.
Re:Bootstrap 5 will remove jQuery as a dependency
by j79 on Tuesday February 12, 2019 @09:24PM
(#19149807)
> PS. The other two answers here are outdated.
Sure, the other two answers may be "outdated" but they're still extremely useful if you're looking to calling map/filter/etc against your queried elements.
Re:Bootstrap 5 will remove jQuery as a dependency
by runarberg on Wednesday February 13, 2019 @01:19AM
(#19150890)
For that you can write:
const elements = document.querySelectorAll('.some-class');
const values = Array.prototype.map.call(elements, element => element.value);
or more idiomatically (and perhaps a little slower): const elements = [...document.querySelectorAll('.some-class')];
const values = elements.map(element => element.value);
Not any more:
https://developer.mozilla.org/en-US/docs/Web/API/NodeList/fo...PS. The other two answers here are outdated.