+ 1

How to combine into one line

the console.log() in JS outputs each item from a new line, how to combine into one line?

10th May 2022, 6:32 PM
Anna Priadkina
11 Respostas
+ 1
console.log(1, 2, 3); // output in a single line
10th May 2022, 6:37 PM
Lisa
Lisa - avatar
+ 1
for example, output in an array loop
10th May 2022, 6:41 PM
Anna Priadkina
+ 1
x = [1, 2]; console.log(...x);
10th May 2022, 6:45 PM
Lisa
Lisa - avatar
+ 1
Form a list or string inside loop. And Output out side loop. I think, you cannot inside loop with console.log() in a single line.
10th May 2022, 6:47 PM
Jayakrishna 🇼🇳
+ 1
console.log('
#x27; + msg.join('
#x27;) + '
#x27;); I managed to display the result, maybe someone will need it
11th May 2022, 9:54 AM
Anna Priadkina
+ 1
If you simply unpack the array, you don't need to construct a string https://code.sololearn.com/cCI7zHjM3xR3/?ref=app
11th May 2022, 10:05 AM
Lisa
Lisa - avatar
0
If this is about code coach task then you need that way to use join or form string in loop. Display at end.
11th May 2022, 10:36 AM
Jayakrishna 🇼🇳
0
I think you can use the follow: const arr = [10 , 20 ,30 , "str"]; console.log(JSON.stringify(arr));
11th May 2022, 6:44 PM
Frank Yohan RodrĂ­guez PĂ©rez
Frank Yohan RodrĂ­guez PĂ©rez - avatar
0
console.log() accepts multiple inputs(items) which should be separated by comma. e.g: let firstName='Anna'; let lastName='Priadkina'; console.log(firstName, lastName);
11th May 2022, 10:05 PM
Mohammad Mohammadizadeh
Mohammad Mohammadizadeh - avatar
0
thanks for the reply, but it's not exactly what you need
12th May 2022, 5:27 AM
Anna Priadkina
0
put all the lines into a variable, then callback the variable using console example var x = "gyuyuyuyuehyuhyuhughayuawghyuuawyugiuawhiuyughukgyuahugfyefkhjgeyakughlEURAAYRyuyuergyuyuayu"; console.log(x); or better still, use different variables and dom to and line breaks to the html or use assignment operator to add string variables
12th May 2022, 12:05 PM
Mikeey
Mikeey - avatar