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

309
Views
How can I save text with formatting in JavaScript?

I'm working on a Chrome Extension that has a notes page as a feature. It's not the main feature (meaning it won't be a lot of text) so I don't need to store the notes in a database, so I plan on storing the notes in LocalStorage.

Is there a way I can store this text with formatting such as new lines. For example, I want the following text:

Hello,

world.

to be saved as is, instead of "Hello,world."

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

To format the text, you need to use:

    const formattedText = text.split('\n').join("\\n")

To get the text back, you should use:

    const text = formattedText.split('\\n').join('\n')
about 4 years ago · Santiago Gelvez 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!