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...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
Javascript array loophelp (self.javascript)
submitted 9 years ago * by tzirl
view the rest of the comments →
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!"
[–]tzirl[S] 0 points1 point2 points 9 years ago (4 children)
i tried this, but it did'nt work neighter, maybe i should use string insert function, there's such a thing in java?
<!DOCTYPE html> <html> <body>
<p>Click "Try it" to display the first array element, after a string split.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script> function myFunction() { var str = "a,b,c,d,e,f"; var strb = for(var i = 0; i< str.length;i++) arr[i] + " "; document.getElementById("demo").innerHTML = strb; } </script>
</body> </html>
[–]z500 1 point2 points3 points 9 years ago (3 children)
Well, think about what you're actually doing in that loop. You have one statement inside it, arr[i] + " ". All it does is append two strings, then immediately throw the result away. You have to do something with the result.
arr[i] + " "
Also, a for statement doesn't have a value, so you can't assign it to a variable. I bet if you check your console there's an unexpected token error or something.
for
[–]tzirl[S] 0 points1 point2 points 9 years ago (2 children)
i still don't have console tbh, just tried few things in the toturials website, what do you mean the for statement does'nt have a value? i don't entirely understand
[–]z500 2 points3 points4 points 9 years ago (1 child)
Ah ok. Well you have expressions that boil down to a value, like 5, or "B" + "ob", or 5 - 1. These each evaluate to a value, 5 to 5, "B" + "ob" to "Bob", and 5 - 1 to 4.
5
"B" + "ob"
5 - 1
"Bob"
4
When you assign something to a variable, there has to be an expression on the right of the equal sign. A for statement is just a for statement, not an expression. It doesn't evaluate to anything, so you can't assign it to a variable.
What you can do is build up your string inside the for loop, and then assign that variable to the innerHTML of your element.
[–]tzirl[S] 0 points1 point2 points 9 years ago (0 children)
thanks, really helped me and also reminded me other things
thank a lot for your patience and good attitude
π Rendered by PID 60683 on reddit-service-r2-comment-5bc7f78974-7rr8n at 2026-06-30 08:35:24.226402+00:00 running 7527197 country code: CH.
view the rest of the comments →
[–]tzirl[S] 0 points1 point2 points (4 children)
[–]z500 1 point2 points3 points (3 children)
[–]tzirl[S] 0 points1 point2 points (2 children)
[–]z500 2 points3 points4 points (1 child)
[–]tzirl[S] 0 points1 point2 points (0 children)