I have a JS function with for loops. Inside the nested for loops, str element prints all of the intended elements. But, outside it doesn't print all of it. I would appreciate any help. Here is my code:
function getResearchersFullName(allDataJson){
var str = [];
var myarr = [];
var c = 0;
for(var i = 0; i < allDataJson.length; i++){
myarr[i] = allDataJson[i].Researchers.split(", ");
for(var j = 0; j < myarr[i].length; j++){
str[c] = myarr[i][j];
//console.log(str[c]); //prints as expected
}
}
return str;
}
I am trying to use the returned value as follows but it only prints one of the str values.
var fullnames = getResearchersFullName(allDataJson);
for(var i = 0; i <fullnames.length; i++){
console.log(fullnames[i]); //returns only 1 object
}