Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print an output in one line using console.log()

Tags:

javascript

Is it possible to print the output in the same line by using console.log() in JavaScript? I know console.log() always returns a new line. For example, have the output of multiple consecutive console.log() calls be:

"0,1,2,3,4,5,"
like image 682
BBKay Avatar asked Feb 20 '15 01:02

BBKay


People also ask

How do I print a new line in console log?

To create a multi line strings when printing to the JavaScript console, you need to add the new line character represented by the \n symbol. Alternatively, you can also add a new line break using Enter when you use the template literals syntax.

How do I print an object in console log?

Answer: Use console. log() or JSON. stringify() Method This method will print the object in browser console.

What is the syntax to print output in a single line?

while x < y: ... print '{0} / {1}, '.

How do I print a console log without a new line?

stdout. write() method to print to console without trailing newline. Note: The process object is global so it can be used without using require() method.


2 Answers

In Node.js there is a way: process.stdout

So, this may work:

process.stdout.write(`${index},`);

where index is a current data and , is a delimiter.

Also you can check same topic here.

like image 106
Alex Glukhovtsev Avatar answered Oct 07 '22 04:10

Alex Glukhovtsev


You could just use the spread operator ...

var array = ['a', 'b', 'c'];

console.log(...array);
like image 27
Jim-chriss Charles Avatar answered Oct 07 '22 04:10

Jim-chriss Charles