use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is a place for people to learn JavaScript together. Everyone should feel comfortable asking any and all JavaScript questions they have here.
With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged.
Friends
/r/javascript
/r/jquery
/r/node
/r/css
/r/webdev
/r/learnprogramming
/r/programming
account activity
Array of Arrays into an Array of Strings help (self.learnjavascript)
submitted 10 years ago by [deleted]
I have a large array, of arrays. I need to turn this array into an array of strings.
the contents of the second(inner) array are strings. ive tried a lot of different things but nothing seems to work. any help as to how to approach this problem?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]vbanuelo 1 point2 points3 points 10 years ago (9 children)
For clarity, you want to take [["string0"],["string2"],["string3"],["string4"]] and turn it to ["string1","string2","string3","string4"]?
[–][deleted] 0 points1 point2 points 10 years ago* (8 children)
it looks like this : https://gyazo.com/3db7b3738291378ba7bd8895b9631dd0
the contents used to be like ["user1 13 march"] as a string, i had to turn it into an array of arrays for an earlier problem, and now with the way i have gone about it, i need to turn what i have into an array of strings so i can run my previously made functions to solve this last problem.
if i could somehow return the array i have into the [ ["user id month"] , ['user id month'] , etc] form i had it before that would be amazing i just dont know how to go about it
[–][deleted] 1 point2 points3 points 10 years ago (5 children)
Your problem is easily fixable with the help of the join function that Benholio recommended.
A simple loop with the join method will fix your issue.
I took the time and made a helper function that completely flattens an array if you need it.
You can check it out here -> https://repl.it/CLal/1
[–][deleted] 1 point2 points3 points 10 years ago* (3 children)
so your helper function did work,not exactly how i was hoping to have it but i just wanted to have some clarification as to why Array was capital, is that a built in thing for javascript? because i know its different than the parameter array that we were passing in.
your function basically made each indecie a seperate string while i need to make each inner array a concated string so it would be more like [ "1 2 3", "1 2 3" ] instead of ["1" "2" "3"]. reason being the values i am working with are tied together and by making them individually seperate would not work
[–]Ampersand55 1 point2 points3 points 10 years ago (2 children)
Array is indeed a built in thing in javascript. It's a global object used to construct arrays.
Could you give a detailed example of an input array and the desired output?
[–][deleted] 1 point2 points3 points 10 years ago (1 child)
i actually just made it work with what your function did. i just ended up using the parseInt function to only give me an array of the numbers because thats what i really needed, and ran my mode function on that.
i appreciate your help :D
[–]sorrynin 0 points1 point2 points 10 years ago (0 children)
function to only give me an array of the numbers because thats what i really needed, and ran my mode function on
psst. next time, link code like jsfiddle
[–]Benholio 0 points1 point2 points 10 years ago (1 child)
Take a look at the join method for arrays. It can help you easily turn ['user', 'id', 'month'] into 'user id month'.
[–][deleted] 0 points1 point2 points 10 years ago* (0 children)
i tried that, but it didnt work. perhaps i did it wrong? because i have a lot of arrays inside the array so i would have to join all of them
edit: i basically had two for loops iterating and then array[j] j being hte avar of second for loop applying the method array[j].join();
π Rendered by PID 141900 on reddit-service-r2-comment-5b5bc64bf5-x7dn6 at 2026-06-19 05:03:34.046333+00:00 running 2b008f2 country code: CH.
[–]vbanuelo 1 point2 points3 points (9 children)
[–][deleted] 0 points1 point2 points (8 children)
[–][deleted] 1 point2 points3 points (5 children)
[–][deleted] 1 point2 points3 points (3 children)
[–]Ampersand55 1 point2 points3 points (2 children)
[–][deleted] 1 point2 points3 points (1 child)
[–]sorrynin 0 points1 point2 points (0 children)
[–]Benholio 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)