Is it possible to print the output in the same line by using console.log in JavaScript?console.log always a new line. For example: " ****** " using loops?
Asked
Active
Viewed 2,009 times
1
-
2possible duplicate of [Chrome JavaScript developer console: Is it possible to call console.log() without a newline?](http://stackoverflow.com/questions/9627646/chrome-javascript-developer-console-is-it-possible-to-call-console-log-withou) – Dan Ross Jun 18 '15 at 06:41
3 Answers
0
No it is not possible to do that.
You can refer this thread: Chrome JavaScript developer console: Is it possible to call console.log() without a newline?

Community
- 1
- 1

Rahul Tripathi
- 168,305
- 31
- 280
- 331
0
What about:
var output = [];
for (i = 0; i < 3; i++) {
output.push('#');
}
console.log(output.join(''));
I'm probably off-topic :-|
0
I'm afraid not. You can't call multiple console.log
and keep it print on the same line. Every single call of console.log
won't append the previous line.
If you want to use loop to print in the same line, this code below will not work at all.
for (var i=0; i<100; i++){
// do something
console.log('*'); // Always prints in a line.
}
If you want to use loop but retain the output in the same line with multiple calls of console.log
. I'm afraid you cannot. You will need to call it once if you want to keep the output on the same line.
Please see the reference in @rahul's answer. That will definitely clarify you very clearly.

TaoPR
- 5,932
- 3
- 25
- 35