how to create line breaks in console.log() in node

后端 未结 7 1572
一生所求
一生所求 2021-01-01 13:11

Is there a way to get new lines in console.log when printing multiple objects?

Suppose we have console.log(a,b,c) where a, b,

相关标签:
7条回答
  • 2021-01-01 13:23

    An alternative is creating your own logger along with the original logger from JS.

    var originalLogger = console.log;
    console.log = function() {
      for (var o of arguments) originalLogger(o);
    }
    
    console.log({ a: 1 }, { b: 3 }, { c: 3 })

    If you want to avoid any clash with the original logger from JS

    console.ownlog = function() {
      for (var o of arguments) console.log(o);
    }
    
    console.ownlog({ a: 1 }, { b: 3 }, { c: 3 })

    0 讨论(0)
  • 2021-01-01 13:28

    Without adding white space at start of new line:-

    console.log("one\ntwo");

    output:-

    one

    two

    This will add white space at start of new line:-

    console.log("one","\n","two");

    output:-

    one

    two

    0 讨论(0)
  • 2021-01-01 13:29

    Another way would be a simple:

    console.log(a);
    console.log(b);
    console.log(c);
    
    0 讨论(0)
  • 2021-01-01 13:35

    Add \n (newline) between them:

    console.log({ a: 1 }, '\n', { b: 3 }, '\n', { c: 3 })

    0 讨论(0)
  • 2021-01-01 13:41

    You need to use \n inside the console.log like this:

    console.log('one','\n','two');
    
    0 讨论(0)
  • 2021-01-01 13:44

    You can use template literal

    console.log(`a is line 1
    b is line 2
    c is line 3`)
    

    to activate template literal you need to click on character to the left of number 1, on my keyboard - Microsoft Wired 600

    DO NOT CONFUSE: ' symbol, that is same as shift + @ on my keyboard with `

    ' and " will create strings and ` will create template literals

    0 讨论(0)
提交回复
热议问题