foreach | Javascript


/ Published in: JavaScript
Save to your folder(s)

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

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


Copy this code and paste it in your HTML
  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

You need to login to post a comment.