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

230
Views
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 answers
Answer question

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 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!