24 ms·
Nice, ['map', 'find', 'filter', 'reduce'].forEach(f => NodeList.prototype[f] = Array.prototype[f]) // this is for for..of, cannot be above 'map', 'filter'
by rofrol 6y ago
Nice,
['map', 'find', 'filter', 'reduce'].forEach(f => NodeList.prototype[f] = Array.prototype[f])
// this is for for..of, cannot be above 'map', 'filter' etc.
NodeList.prototype[Symbol.iterator] = Array.prototype[Symbol.iterator]
document.querySelectorAll('span').map(el => console.log(el))
document.querySelectorAll('span').filter(el => el.className === 'fc-black-500').reduce((acc, el) => (acc += el.className, acc), '')
for(let p of document.querySelectorAll('p')) { console.log(p) }
- https://stackoverflow.com/questions/30836289/for-of-loop-queryselectorall https://stackoverflow.com/questions/30836289/for-of-loop-que...
- megous 6y agoYou can also create a getter on NodeList.prototype named '_' that returns Array.from(this) and then just use any of the array methods on it. Like document.querySelectorAll('div')._.some(...) So many options. :)