Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. var forEach = function (array, callback, scope) {
  2. for (var i = 0; i < array.length; i++) {
  3. callback.call(scope, i, array[i]); // passes back stuff we need
  4. }
  5. };
  6.  
  7. // Usage:
  8. // optionally change the scope as final parameter too, like ECMA5
  9. var myNodeList = document.querySelectorAll('td:nth-child(3) > a');
  10. forEach(myNodeList, function (index, value) {
  11. console.log(index, value.textContent); // passes index + value back!
  12. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement