Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

307
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda