pdo*_*926 5 javascript coffeescript
在未命名的数组上使用forEach循环时,有没有办法访问目标对象的长度属性?
# I'd like to be able to do something like:
[1, 2, 3].forEach (n, i) -> console.log n is < (arr.length - 1)
Run Code Online (Sandbox Code Playgroud)
Array.forEach
采用树参数的回调:值,索引和遍历的数组.
所以你可以这样做:
[1, 2, 3].forEach (n, i, thearray) -> console.log n is < (thearray.length - 1)
Run Code Online (Sandbox Code Playgroud)
使用Javascript:
[1, 2, 3].forEach(function(n, i, thearray) {
console.log(n < thearray.length - 1);
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
169 次 |
最近记录: |