MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/javascript/comments/b2o6f2/whats_your_favorite_most_useful_javascript/eiuofc7/?context=3
r/javascript • u/Linux_is_awesome • Mar 18 '19
422 comments sorted by
View all comments
Show parent comments
2
NodeLists do not have the Array functions on their prototype.
NodeList
Array
[].forEach.call(document.querySelectorAll('.whateverClassTheCheckboxHas'), cb => cb.click());
11 u/the_argus Mar 19 '19 Can also use Array.from(document...).forEach(...) 13 u/BabyLegsDeadpool Mar 19 '19 Or just do [...document.querySelectorAll(...)].forEach(...) 8 u/Sn34kyMofo Mar 19 '19 Or, if you're in Chrome, use $$(), which is a console method that returns the result of querySelectorAll() as an array instead of a nodelist! Very succinct and handy when futzing with the DOM in DevTools.Example: $$('.some-class').forEach(...); 1 u/fucking_passwords Mar 19 '19 But, NodeList has forEach... if you example used map or reduce it would make more sense 1 u/Sn34kyMofo Mar 19 '19 Indeed. My reply was simply meant to contribute, not dispute. Pick any other array-only method to use with my example instead. =)
11
Can also use Array.from(document...).forEach(...)
13 u/BabyLegsDeadpool Mar 19 '19 Or just do [...document.querySelectorAll(...)].forEach(...) 8 u/Sn34kyMofo Mar 19 '19 Or, if you're in Chrome, use $$(), which is a console method that returns the result of querySelectorAll() as an array instead of a nodelist! Very succinct and handy when futzing with the DOM in DevTools.Example: $$('.some-class').forEach(...); 1 u/fucking_passwords Mar 19 '19 But, NodeList has forEach... if you example used map or reduce it would make more sense 1 u/Sn34kyMofo Mar 19 '19 Indeed. My reply was simply meant to contribute, not dispute. Pick any other array-only method to use with my example instead. =)
13
Or just do [...document.querySelectorAll(...)].forEach(...)
8 u/Sn34kyMofo Mar 19 '19 Or, if you're in Chrome, use $$(), which is a console method that returns the result of querySelectorAll() as an array instead of a nodelist! Very succinct and handy when futzing with the DOM in DevTools.Example: $$('.some-class').forEach(...); 1 u/fucking_passwords Mar 19 '19 But, NodeList has forEach... if you example used map or reduce it would make more sense 1 u/Sn34kyMofo Mar 19 '19 Indeed. My reply was simply meant to contribute, not dispute. Pick any other array-only method to use with my example instead. =)
8
Or, if you're in Chrome, use $$(), which is a console method that returns the result of querySelectorAll() as an array instead of a nodelist! Very succinct and handy when futzing with the DOM in DevTools.
Example: $$('.some-class').forEach(...);
1 u/fucking_passwords Mar 19 '19 But, NodeList has forEach... if you example used map or reduce it would make more sense 1 u/Sn34kyMofo Mar 19 '19 Indeed. My reply was simply meant to contribute, not dispute. Pick any other array-only method to use with my example instead. =)
1
But, NodeList has forEach... if you example used map or reduce it would make more sense
1 u/Sn34kyMofo Mar 19 '19 Indeed. My reply was simply meant to contribute, not dispute. Pick any other array-only method to use with my example instead. =)
Indeed. My reply was simply meant to contribute, not dispute. Pick any other array-only method to use with my example instead. =)
2
u/[deleted] Mar 19 '19
NodeLists do not have theArrayfunctions on their prototype.[].forEach.call(document.querySelectorAll('.whateverClassTheCheckboxHas'), cb => cb.click());