How to continue output to the console, when console.log() called, not from a new line every time, but continue to output text to the current line?

  • one
    write data to a variable and finally output it to the console? - Necro The Human

2 answers 2

This is done simply. Here is an example:

 var cars = { a184bx154:'Хонда инспаер', b397ax54:'Лада калина', x888xx77:'Ешка', o777oo140:'Беха X5' }; var index = 0; var log = ''; for(var key in cars) { index++; log+='№'+index+') машина '+cars[key]+' с номером '+key+';' } console.log(log); 

You need to write to a variable and at the end use console.log to output what you have written.

  • This method does not suit me. In my case, you need to add data to the line at different times. - AND
  • This is not a string - a variable, but a console string. - AND
  • @AND You can not control the record in the console after the output. - Geri4
  • Ok, let me not be able to control the record in the console after it is output, but at least you can force consol.log () to output a line without a newline character at the end? - AND
  • one
    @AND it doesn't work like that. habrahabr.ru/post/114483 is a very good article on the console, maybe it will add an understanding of what the console is in js - Geri4

Indeed console.log () always inserts the end of line character in the end and it is not possible to change it.

The problem in this case is completely solved by the following method: process.stdout.write ()

  • if you specify a method specific to a specific runtime environment, it is better to indicate where it will work. For example, there is no process in the browser - Grundy