[英]Is it possible to manipulate the index parameter of Array.prototype.reduce?
Normally the index value of Array.prototype.reduce takes the values from 0 until the Array.length. 通常,Array.prototype.reduce的索引值采用从0到Array.length的值。 Is it possible to manipulate that value so that it starts from Array.length and descends to 0?
是否有可能操纵该值,使其从Array.length开始并下降到0?
您可以始终为此使用Array.prototype.reduceRight() 。
No, but you could always do this... 不,但是您可以始终这样做...
var yourNumber = arr.length - 1 - index;
...or Array.prototype.reduceRight()
which will loop from last index to first (in reverse). ...或
Array.prototype.reduceRight()
将从最后一个索引循环到第一个(相反)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.