Chrome JavaScript developer console: Is it possible to call console.log() without a newline?

前端 未结 12 860
生来不讨喜
生来不讨喜 2020-11-29 05:07

I\'d like to use console.log() to log messages without appending a new line after each call to console.log(). Is this possible?

12条回答
  •  南方客
    南方客 (楼主)
    2020-11-29 05:35

    collect your output in an array and then use join function with a preferred separator

    function echo(name, num){
        var ar= [];
        for(var i =0;i

    check also Array.prototype.join() for mode details

    var elements = ['Fire', 'Wind', 'Rain'];
    
    console.log(elements.join());
    // expected output: Fire,Wind,Rain
    
    console.log(elements.join(''));
    // expected output: FireWindRain
    
    console.log(elements.join('-'));
    // expected output: Fire-Wind-Rain
    

提交回复
热议问题