ArrayLike (AL07)
1: function mapArrayLike(arrayLike, callback) {
2: const result = [];
3: for (let i = 0; i < arrayLike.length; i++) {
4: result.push(callback(arrayLike[i], i, arrayLike)); // Similar signature to Array.map()'s callback
5: }
6: return result;
7: }
8:
9: const nodeList = document.querySelectorAll('p');
10: const textContent = mapArrayLike(nodeList, node => console.log(node));
11:
ArrayLike context:
ES6 context:
Comments (
)

Link to this page:
http://www.vb-net.com/JavascriptES6/AL07.htm
|