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

前端 未结 12 886
生来不讨喜
生来不讨喜 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:38

    // Source code for printing 2d array
    window.onload = function () {
        var A = [[1, 2], [3, 4]];
        Print(A);
    }
    
    function Print(A) {
        var rows = A.length;
        var cols = A[0].length;
        var line = "";
        for (var r = 0; r < rows; r++) {
            line = "";
            for (var c = 0; c < cols; c++) {
                line += A[r][c] + " ";
            }
            console.log(line);
        }
    }
    

提交回复
热议问题