Trying to find the intersection of two arrays, why am I getting TS2339:Property 'collection' does not exist on type 'void'?
All arrays are declared in the same class.
this.locations.forEach(function(location) {
this.collection.locations.forEach(function(id) {
if(location._id === id) {
this.display.push(location);
}
});
});
Using a function takes the this from the caller (something in forEach in your case); using => takes the this from the outer scope. Thus use:
this.locations.forEach(location => {
this.collection.locations.forEach(id => {
if(location._id === id) {
this.display.push(location);
}
});
});
I recommend the following readings:
thisIf 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