JavaScript's forEach documentation states that the .forEach
syntax is:
arr.forEach(callback[, thisArg])
What is the usage of thisArg
?
thisArg
refers to context which callback should be called,
basically it is what this
refers to inside callback. For example:
var myObject = { name: 'myObject' };
[1,2].forEach(function(item) {
console.log(item); // 1, 2
console.log(this === myObject); // true
}, myObject)
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