I want to console.log my array like this without newlines:
const myarr = [ 1, 2, 3, 4, 5 ];
myarr.forEach((e) => console.log(e));
Actual result:
1
2
3
4
5
Desired result:
1 2 3 4 5
or
12345
You could spread the array. Then all values are taken as parameters.
let array = [1, 2, 3, 4, 5];
console.log(...array);
To answer the actual question, there are two possible answers:
process.stdout.write(msg) from this answer Chrome JavaScript developer console: Is it possible to call console.log() without a newline?If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With