Welcome 微信登录

首页 / 脚本样式 / JavaScript / 为原生js Array增加each方法

复制代码 代码如下:
Array.prototype.each = function(fn)
{
return this.length ? [fn(this.slice(0,1))].concat(this.slice(1).each(fn)) : [];
};

[1,2,3,4].each(function(x){
document.write(x + "<br/>");
});