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

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.


Couldn't you just put them in the same call, or use a loop?

  var one = "1"
  var two = "2"
  var three = "3"

  var combinedString = one + ", " + two + ", " + three

  console.log(combinedString) // "1, 2, 3"
  console.log(one + ", " + two + ", " + three) // "1, 2, 3"

  var array = ["1", "2", "3"];
  var string = "";
  array.forEach(function(element){
      string += element;
  });
  console.log(string); //123

You could just use the spread operator ...

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

console.log(...array);

Tags:

Javascript