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

306
Views
How to remove backslash in a string in React?

I'm very new to React. I'm trying to remove backslash from a string.

[

  {

    "Roll no": 33,
    "Name" : "<p class=\"nameclass\"> \n Rakesh </p>";
 }

]

I want to remove slash in a class and and output will be

<p class="nameclass">Rakesh</p>

Thanks

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

You can simply use replaceAll :

string_with_backslash.replaceAll('\\','')

This will remove backslashes except for the new line slash(\n).

about 4 years ago · Juan Pablo Isaza Report

0

EDIT: ignore this. The correct answer is provided in the comment by @T.J. Crowder.

It appears you're receiving JSON data via an API. The data will arrive as a STRING and you can parse it to get an OBJECT.

const myJSONData = JSON.parse(response.data)

Can you find out how the server "encodes" the data being sent to you? Understanding what is done in that step is critical to being able to "decode" the data back to the original state. The server is probably stringifying the entire structure, but they may be calling encodeURIComponent or doing other processing that you need to be aware of.

about 4 years ago · Juan Pablo Isaza Report

0

You can use regular expression and replace to remove the backlash and \n from your string.

use the following code :

let a = "<p class=\"nameclass\"> \n Rakesh </p>";
let n = a.replace(/\n/,"")

output : '<p class="nameclass">  Rakesh </p>'

replace will not do changes in the original string, so store the value in a different string.

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!