Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
JavaScript console.log: How to make the comma param separator use newline for objects instead of space?

When I write something like:

console.log("data", data);

where data is an object, it'll print "data [some form of the object]" where [some form of the object] is typically a collapsed object with expand arrows that I can click to view the object's elements.

However, this can become painful when the preceding text line is long and there's a lot of output... and I'd rather have that object start on the next line, which makes me either add another console.log just for that object, or add a \n to the preceding line string.

Since console.log('whatever', whatever) appends a space to 'whatever' when a comma follows it, I'd like some way to specify 'use a newline in this case, or for objects following the comma', but I'm not seeing how to do that.

Is this possible in any way?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can use console.dir and the document for it here: https://developer.mozilla.org/en-US/docs/Web/API/console/dir

about 4 years ago · Juan Pablo Isaza Report

0

You need another function that wrapps the console.log(),

fancyLog  = function(...args){
    args.forEach( arg=>{
        console.log( arg );
    } );
}

this wrapper function will get your task done.

about 4 years ago · Juan Pablo Isaza Report

0

The short answer is no, what you are asking doesn't exist just like that.

You can hack it by doing something like:

console.log(`whatever\n${JSON.stringify(whatever, null, 2)}`);

Which will print the object in json in the next line. Or if you don't need that, just:

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

But it's debatable how much work it really saved from just adding two console.logs.

Your final option is to use console.dir or console.table following that console.log, but again it doesn't save you from having to place two lines there.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!