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

231
Vistas
How to delete a text in a string?

How to delete a text in a string?

I need to delete a certain text in a string that the backend sends me (client name)

The string is one of the following:

Mr. Alan Turing (DNI: 012345678901234)
Mr. Charles Babbage (DNI: 97845565)
Mr. Stephen Wozniak (DNI: 6448775)

I need to eliminate the text that is in parathesis including the parentheses, I should only have the name of the client

To extract the name of the client I do it as follows:

const customer_name = document.querySelector("#Txt_customer_name > b")

the customer name field is a dynamic field but it always has the same structure

First name + last name (Customer DNI)

The result I expect is:

Mr. Alan Turing
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use customer_name.innerHTML.split(" (DNI: ")[0]

const customer_name = document.querySelector("#Txt_customer_name > b");

console.log(customer_name.innerHTML.split(" (DNI: ")[0])
<div id="Txt_customer_name"><b>Mr. Alan Turing (DNI: 012345678901234)</b></div>

For multiple elements use a loop

const customer_name = document.querySelectorAll("#Txt_customer_name > b");

customer_name.forEach(el => console.log(el.innerHTML.split(" (DNI: ")[0]))
<div id="Txt_customer_name">
  <b>Mr. Alan Turing (DNI: 012345678901234)</b>
  <b>Mr. Charles Babbage (DNI: 97845565)</b>
  <b>Mr. Stephen Wozniak (DNI: 6448775)</b>
</div>

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