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

162
Vistas
JavaScript how to replace dots with a break line in a string

In my project I have a form for messages the user can send to me, when the validation fail I need to display the errors for him, but the errors the I get from the backend is an object of arrays and I extracted the values and concatenated it in one string by this

    let errors = Object.values(data);
    let errorsMarkup = ""

    for (let i = 0; i < errors.length; i++) {
      errorsMarkup += `${errors[i]}`;
    }

now the string will be sentences that shows the errors separated by dots, I need it to be separated by break lines to show the user the errors one by line so I made this

    errorsMarkup = errorsMarkup.replace(/\./g,'<br>');

and I call the sweet alert to show the errorsMarkup

    Swal.fire({
      icon: 'error',
      title: 'Oops...',
      text: errorsMarkup
    });

but this is what I get

The Output

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Use html property to pass HTML

Swal.fire({
  icon: 'error',
  title: 'Oops...',
  text: '',
  html: errorsMarkup
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

Try replacing text with html:

Swal.fire({
  icon: 'error',
  title: 'Oops...',
  html: errorsMarkup
});

You can refer to the official docs for help: https://sweetalert2.github.io/#usage

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