Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
82
rated 0 times [  87] [ 5]  / answers: 1 / hits: 109345  / 9 Years ago, mon, october 12, 2015, 12:00:00

I'm trying to get the output from my for loop to print in a single line in the console.



for(var i = 1; i < 11; i += 1) {
console.log(i);
}


Right now it's



1
2
3
4
5
6
7
8
9
10


How can I get the output all in one line (like this
1 2 3 4 5 6 7 8 9 10)?


More From » loops

 Answers
6

Build a string then log it after the loop.





var s = ;
for(var i = 1; i < 11; i += 1) {
s += i + ;
}
console.log(s);




[#64761] Friday, October 9, 2015, 9 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
christianu

Total Points: 481
Total Questions: 124
Total Answers: 99

Location: Trinidad and Tobago
Member since Thu, Dec 1, 2022
2 Years ago
christianu questions
;