function - How to access a variable outside of a nested for loop in JavaScript -


i have js function loops. inside nested loops, str element prints of intended elements. but, outside doesn't print of it. appreciate help. here code:

function getresearchersfullname(alldatajson){     var str = [];     var myarr = [];     var c = 0;     for(var = 0; < 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 expected         }     }      return str; } 

i trying use returned value follows prints 1 of str values.

var fullnames = getresearchersfullname(alldatajson);          for(var = 0; <fullnames.length; i++){                 console.log(fullnames[i]); //returns 1 object          } 

your code never increments c. element of str that's ever modified element 0.

use str.push(myarr[i][j]); , won't need c @ all.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -