How to build a simple string from a multidimensional array?
Basically, I have a multidimensional array that I need to build into a
simple string.
Quite an easy question, although it has been eating away at me for quite
some time now since I can't seem to nail it.
Here is an example of how my array could look with just 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] would be "question1" and D.rows[2][3] would be
"answer3", just to clarify.
Here is how it must be saved into a string as:
question1,answer1,answer2,answer3,answer4
question2,answer1,answer2,answer3,answer4
question3,answer1,answer2,answer3,answer4
Each element must have a comma between them, and each question must be
separated by a line-break.
I had this working with a foreach loop in PHP, although I decided to
convert all my code to Javascript and I am no expert when it comes to
Javascript or multidimensional arrays.
Thanks in advance!
No comments:
Post a Comment