Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

260
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda