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

160
Views
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 answers
Answer question

0

Use html property to pass HTML

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

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