function newforEach(obj,fn) { var key; if(obj instanceof Array){ obj.forEach(function(item,index){ fn(item,index); }) }else { for(key in obj){ fn(key,obj[key]); } } }var arr = [1,2,3]; newforEach(arr,function (item,index) { console.log(item); });var…