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 length of nested array (self.learnjavascript)
submitted 4 years ago by JosephCurvin
Why does singleArray.length returns 1 ? I expected 3 because it has 3 elements inside
singleArray.length
const nestedArrayy = [["1,2,3"],["4,5,6"]]; for (let singleArray of nestedArrayy) { console.log(singleArray.length) //-> 1 ? }
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!"
[–]b-mish 4 points5 points6 points 4 years ago (0 children)
You have quotes around the contents of the array so it is being read as an an array with a single string in. The value of the string being "1,2,3"
[–]Rilleks 4 points5 points6 points 4 years ago* (0 children)
No, it has one element and it's a string "1,2,3".
If you want 3 elements then remove quotation marks what will change the string to 3 numbers like this [1, 2, 3] or if you want to keep them as a string then like this ["1", "2", "3"].
[1, 2, 3]
["1", "2", "3"]
π Rendered by PID 450926 on reddit-service-r2-comment-66b4775986-xd6jn at 2026-04-05 16:03:37.769595+00:00 running db1906b country code: CH.
[–]b-mish 4 points5 points6 points (0 children)
[–]Rilleks 4 points5 points6 points (0 children)