Scratching my head. I'm getting an undefined error when trying to call a function. Thing is, when I print to the console I can see the data being passed clearly.
Uncaught TypeError: convos is undefined
function1
function fetchConversation(userID){
//loop through
usersms.forEach(function (sms,counter) {
//get userid from iteration
var userid_loop = sms.details[0].user.id;
//only display convo from specific user
if(userid_loop === userID){
//get all messages from this one user
var conversation = sms.details;
//transfer conversation to next function to display
showConversation(conversation);
//
}
//
});
}
function2
function showConversation(myconvo){
var convos = myconvo;
//iterate and append conversion
convos.forEach(function (msg,counter) {
console.log(msg.message);//prints all messages in the log
});
}
showConversation()//Uncaught TypeError: convos is undefined
showConversation(myconvo)instead ofshowConversation()showConversation()on its own?showConversation(), you have passed no arguments, meaningmyconvoisundefined. Then you try to doundefined.forEach, which will explode because it's not an array.