Guest User

Untitled

a guest
Oct 22nd, 2017
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. function each(object, callback) {
  2. var item;
  3.  
  4. if (object.length != null) {
  5. // for array with an empty string in it, the conditional causes iteration to stop at the empty string
  6. for (var i = 0; i < object.length; i++) {
  7. callback(object[i], i);
  8. }
  9. } else {
  10. for (var key in object) {
  11. if (object.hasOwnProperty(key)) {
  12. callback(object[key], key);
  13. }
  14. }
  15. }
  16. }
Add Comment
Please, Sign In to add comment