Home >Web Front-end >JS Tutorial >Add each method to native js Array_javascript skills

Add each method to native js Array_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:54:40941browse
复制代码 代码如下:

   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 "
");
});
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn