Javascript for loop console print in one line

前端 未结 6 1964
时光取名叫无心
时光取名叫无心 2020-12-29 14:02

I\'m trying to get the output from my for loop to print in a single line in the console.

for(var i = 1; i < 11; i += 1) {
    console.log(i);
}

6条回答
  •  醉话见心
    2020-12-29 14:37

    Build a string then log it after the loop.

    var s = "";
    for(var i = 1; i < 11; i += 1) {
      s += i + " ";
    }
    console.log(s);

提交回复
热议问题