JS_Sakib
JS_Sakib

Reputation: 13

How can I print multiple arrays on separate lines using same console.log?

My output right now is this: Output

My code is:

var a = [2, 4];
var b = [5, 6];

console.log(a, "\n", b);

I want the output to look like this:

[2, 4]
[5, 6]

Upvotes: 1

Views: 952

Answers (4)

AyesC
AyesC

Reputation: 303

Try using the array.toString() function.

var a = [2, 4];
var b = [5, 6];

console.log(a.toString() + '\n' + b.toString())

This code would return:

2,4
5,6

Upvotes: 0

evgzabozhan
evgzabozhan

Reputation: 150

I think you can use

var a = [2, 4];

var b = [5, 6];

console.log(a + "\n" + b);

It's working for me.

Upvotes: 2

Aib Syed
Aib Syed

Reputation: 3196

Here's one way:

var a = [2, 4];

var b = [5, 6];

console.log('',a,'\n',b)

Upvotes: 2

Marcus Cantu
Marcus Cantu

Reputation: 493

You can use this:

console.log(`${a}\n${b}`);

Upvotes: 1

Related Questions