Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

242
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda