使用console.log()在一行中输出输出 [英] Print an output in one line using console.log()

查看:167
本文介绍了使用console.log()在一行中输出输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过在JavaScript中使用 console.log()在同一行中打印输出?我知道 console.log()总是返回新行.例如,使多个连续的 console.log()调用的输出为:

Is it possible to print the output in the same line by using console.log() in JavaScript? I know console.log() always returns a new line. For example, have the output of multiple consecutive console.log() calls be:

"0,1,2,3,4,5,"

推荐答案

难道不能只是将它们放在相同的调用中,还是使用循环?

Couldn't you just put them in the same call, or use a loop?

var one = "1"
var two = "2"
var three = "3"

var combinedString = one + ", " + two + ", " + three

console.log(combinedString) // "1, 2, 3"
console.log(one + ", " + two + ", " + three) // "1, 2, 3"

var array = ["1", "2", "3"];
var string = "";
array.forEach(function(element){
    string += element;
});
console.log(string); //123

这篇关于使用console.log()在一行中输出输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆