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

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

0

Use html property to pass HTML

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

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 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