We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ECMAScript 5新增了两个数组的归并方法:reduce() 和 reduceRight() 。 这两个方法都会迭代数组的所有项,然后构建最终的一个返回值。reduce() 方法从数组的第一项开始,逐个遍历到最后;reduceRight() 方法则从最后一项开始,向前遍历到第一项。
var numbers=[1,2,3,5,6,7,8]; var reduceTotal=numbers.reduce(function(prev,cur,index,array){ return prev+cur; }); console.log(reduceTotal); //32 var reduceRightTotal=numbers.reduceRight(function(prev,cur,index,array){ return prev+cur; }); console.log(reduceRightTotal); //32
浏览器支持:IE9+
The text was updated successfully, but these errors were encountered:
No branches or pull requests
ECMAScript 5新增了两个数组的归并方法:reduce() 和 reduceRight() 。 这两个方法都会迭代数组的所有项,然后构建最终的一个返回值。reduce() 方法从数组的第一项开始,逐个遍历到最后;reduceRight() 方法则从最后一项开始,向前遍历到第一项。
The text was updated successfully, but these errors were encountered: