Javascript 访问array.forEach中的未命名数组
在未命名数组上使用forEach循环时,是否有任何方法可以访问目标对象的length属性Javascript 访问array.forEach中的未命名数组,javascript,coffeescript,Javascript,Coffeescript,在未命名数组上使用forEach循环时,是否有任何方法可以访问目标对象的length属性 # I'd like to be able to do something like: [1, 2, 3].forEach (n, i) -> console.log n is < (arr.length - 1) #我希望能够做到以下几点: [1,2,3].forEach(n,i)->console.log nconsole.log n是
# I'd like to be able to do something like:
[1, 2, 3].forEach (n, i) -> console.log n is < (arr.length - 1)
#我希望能够做到以下几点:
[1,2,3].forEach(n,i)->console.log n<(arr.length-1)
回调采用树参数:值、索引、和正在遍历的数组
所以你可以这样做:
[1, 2, 3].forEach (n, i, thearray) -> console.log n is < (thearray.length - 1)
[1,2,3].forEach(n,i,thearray)->console.log n是<(thearray.length-1)
Javascript:
[1, 2, 3].forEach(function(n, i, thearray) {
console.log(n < thearray.length - 1);
});
[1,2,3].forEach(函数(n,i,数组){
console.log(n
嗯,它是一个常量数组,因此您知道长度。在这个例子中,它是3。你需要它做什么?@daniel kullmann,这个问题同样适用于getSomething()。forEach…
Note to self,