Is there any way to access the target object's length property when using the forEach loop over an unnamed array?
# I'd like to be able to do something like:
[1, 2, 3].forEach (n, i) -> console.log n is < (arr.length - 1)
The callback of Array.forEach
takes tree arguments: value, index, and the array being traversed.
So you can do that:
[1, 2, 3].forEach (n, i, thearray) -> console.log n is < (thearray.length - 1)
Javascript:
[1, 2, 3].forEach(function(n, i, thearray) {
console.log(n < thearray.length - 1);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With