Posted By

mattkenefick on 11/03/10


Tagged

code best written ive ever


Versions (?)

Who likes this?

5 people have marked this snippet as a favorite

mattkenefick
liamchapman
Tyster
crd
guo3823538


foreach | Javascript


 / Published in: JavaScript
 

I should've wrote this function a LONGGG time ago.

foreach($myArray, function($k, $v){ console.log($k + " :: " + $v); });

  1. function foreach($haystack, $callback){
  2. for(var i in $haystack){
  3. if(typeof($haystack[i]) != 'function'){
  4. $callback(i, $haystack[i]);
  5. };
  6. };
  7. };

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: tarini on November 4, 2010

What about scoping? Your code doesn't consider this!

Posted By: mattkenefick on November 5, 2010

what ABOUT scoping?

You need to login to post a comment.