I get feedback from the server in JSON . There are paragraph separators \n in the text, but if you output this review through console.log() then there are no such hyphenations as in the html when I insert this text. How can I break the review text into paragraphs for this separator?

 JSON { text: "Заказал что-то там. \nЕщё какой-то текст. \nСпасибо вам большое за работу." } 

Console output - no transfers

 Заказал что-то там. Ещё какой-то текст. Спасибо вам большое за работу. 
  • but just on the css is not an option? - user33274

1 answer 1

You can replace all hyphens with a transfer tag with a regular expression <br>

 const text = "Заказал что-то там. \nЕщё какой-то текст. \nСпасибо вам большое за работу." document.body.innerHTML = text.replace(/\n/g, '<br>'); 

Or display text in the <pre></pre> it saves hyphens and spaces.

Or break into an array and loop each paragraph in the new <p>

 const text = "Заказал что-то там. \nЕщё какой-то текст. \nСпасибо вам большое за работу."; const p = text.split('\n'); //["Заказал что-то там. ", "Ещё какой-то текст. ", "Спасибо вам большое за работу."] 
  • 2
    Hi, XSS attack - andreymal
  • one
    @andreymal how do you define an attack? - user33274