javascript - How to build a simple string from a multidimensional array? -
basically, have multidimensional array need build simple string.
quite easy question, although has been eating away @ me quite time since can't seem nail it.
here example of how array 3 questions within it:
[["question1","answer1","answer2","answer3","answer4"],["question2","answer1","answer2","answer3","answer4"],["question3","answer1","answer2","answer3","answer4"]]
for example, d.rows[0][0]
"question1" , d.rows[2][3]
"answer3", clarify.
here how must saved string as:
question1,answer1,answer2,answer3,answer4 question2,answer1,answer2,answer3,answer4 question3,answer1,answer2,answer3,answer4
each element must have comma between them, , each question must separated line-break.
this have not working:
var fullstring; (i = 0; < csvarray.length; ++i) { second = secondarray[i]; (j = 0; j < second.length; ++j) { fullstring += entry[j] + "'"; } fullstring += "\n"; }
thanks in advance!
try this
var s,a=[["question1","answer1","answer2","answer3","answer4"],"question2","answer1","answer2","answer3","answer4"],["question3","answer1","answer2","answer3","answer4"]]; for(i=0; < a.length; i++){ s=(s)?s+"\n\r"+a[i].join():a[i].join(); }
in own example: since going straight adding fullstring
, should have empty string value, otherwise end undefined
in beginning.
var fullstring="";
this part second = secondarray[i];
should have been
var second = csvarray[i];
and in same way fullstring += entry[j] + "'";
should have been
fullstring += second[j] + ",";
Comments
Post a Comment