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

225
Views
Array.Prototype.Filter no elimina un elemento que si se encuentra con include()

Estoy tratando de eliminar un elemento de una matriz. Hay una verificación simple para determinar si el elemento se agregó y, si es cierto, estoy tratando de usar el filtro para eliminarlo, pero esto no funciona. No entiendo cómo include() puede encontrar el elemento coincidente, pero luego, al intentar filtrarlo, ¿no lo eliminará? El elemento en cuestión es solo un uuid.

 const AddCheckedPriv = (PrivIdToAdd) => { if (newUser.privilege_groups.includes(PrivIdToAdd)) { console.log("includes"); let newPrivilegeGroups = newUser.privilege_groups; newPrivilegeGroups.filter((priv) => priv != PrivIdToAdd); console.log(newPrivilegeGroups.find(PrivIdToAdd)); } else { let newPrivilegeGroups = newUser.privilege_groups; newPrivilegeGroups = [...newPrivilegeGroups, PrivIdToAdd]; setNewUser({ ...newUser, privilege_groups: newPrivilegeGroups }); } };

Gracias,

greg

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

0

.filter no muta la matriz existente en el lugar. (Eso sería un problema en React, después de todo). Devuelve una nueva matriz. Debe asignar el resultado a una variable, o registrar el resultado, o algo así. En este momento, simplemente lo estás ignorando.

 if (newUser.privilege_groups.includes(PrivIdToAdd)) { let newPrivilegeGroups = newUser.privilege_groups.filter((priv) => priv !== PrivIdToAdd);
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!