I am trying to get the value of this.userId
while inside the second for loop, it throughs undefined
.
Have a look at the code below:
//the following variable gets undefined inside the second for loop
this.userId = localStorage.getItem('userId');
this.reviews.forEach(function(element1){
element1.usersWhoLike.forEach(function(element2) {
if(element2 == this.userId){
//this throughs undefined !!
console.log('UserID is : ',this.userId)
}
});
});