My for-each implementation I have implemented for-each as in jQuery, this is the code below,

var $ = (function(){
   var obj = {};
   return obj;
})();

$.each = function(collection,fn){

    if(collection.constructor.name === 'Array'){
        for(var i = 0; i &lt; collection.length; i++){
            fn.call(this,collection[i]);
        }   
    }else{
        for(var prop in collection){
            fn.call(this,collection[prop]);
        }
    }


};


$.each([1,2,3,7,8],function(num){
    console.log(num * 2);
});

$.each(['A','B','C'],function(char){
    console.log(char);
});

$.each({ 
    name : 'Rahul Shivsharan', 
    department : 'Computer Science' 
},function(value){
       console.log(value);
});


The output of the code is

2
4
6
14
16 
A
B
C
Rahul Shivsharan
Computer Science


Please review my jQuery style for-each implementation, and let me know your feedback
To extend jQuery EACH I think it will confuse other developers especially during the maintenance period without you. To be better looping your collections you may need to use UnderscoreJS vs Lodash. They come with many useful collection functions.