While inside the second for loop, I am attempting to retrieve the value of this.userId
. However, it is returning undefined
. Let's take a look at the code snippet below:
// The following variable becomes undefined within the second for loop
this.userId = localStorage.getItem('userId');
this.reviews.forEach(function(element1){
element1.usersWhoLike.forEach(function(element2) {
if(element2 == this.userId){
// This results in undefined !!
console.log('UserID is : ', this.userId)
}
});
});