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

222
Views
¿Cómo buscar duplicados en la lista (javascript)?

Trato de buscar duplicados en la matriz y obtengo un error, y me alegro de cualquier solución para este problema. Se adjunta el código:

 let names = itemList[0].getElementsByTagName("span")[0].innerText; for (i = 1; i < itemList.length; i++) { if (!(itemList[i].getElementsByTagName("span")[0].innerText in names)) { names.push(itemList[i].getElementsByTagName("span")[0].innerText); } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puedes usar indexOf. Si el índice de ese elemento en la matriz que está tratando de enviar es -1, eso significa que no existe y que puede continuar y enviarlo. De lo contrario, no haga nada. También puede revertir esto y agregar a la matriz desde la otra si ya existe, y no hacer nada si no existe.

Ejemplo:

 const array = [1, 2, 3, 4, 5, 6, 7, 8]; // We are adding this. Expecting to not add the numbers that are already there const toPushTo = [1, 10, 5]; const addToArrayIfNotDuplicate = (arr)=> { arr.forEach(item=>{ toPushTo.indexOf(item) === -1 ? toPushTo.push(item) : null; }) }; addToArrayIfNotDuplicate(array); console.log(toPushTo);

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!