Why is the object undefined, if I call it in arr.find with 'this'?
let o = { name: 'foobar' };
let arr = [3, o, 4, 5];
arr.find(x => console.log(this), o);
If you want to use the second parameter of find() to set this you need to pass a regular function because you can't re-bind this to arrow functions:
let o = { name: 'foobar' };
let arr = [3, o, 4, 5];
let p = arr.find(function(x){
console.log(this)
return x === this
}, o);
console.log("found:", p)
bind(someObj) on an arrow function to set the value of this find()'s second param is a value to rebind the function to. Maybe I phrased it poorly.
thisfrom the current scope, and so your code logswindowfour times. It works as expected if you convert the lambda to a regular anonymous function. Your callback doesn't return a truthy value though, so it won't ever find anything.thisto refer to? From what you posted it's not clear why exactly it'sundefined, but it would not be weird for it to beundefined.