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

249
Views
Si la matriz incluye una clave determinada, elimine el objeto completo usando JS

Recibo una matriz 2d y, a veces, obtengo un "error" y un "mensaje" para ese objeto en particular. El problema con el que sigo enfrentándome es que los mensajes que recibo varían... ¿Cómo hago si se menciona la tecla "error" y luego elimino el objeto por completo?

Mi matriz:

 let filtData = [ [ { descriptions: { attrs: { lang: "en-GB", }, }, }, { descriptions: { attrs: { lang: "es", }, }, }, { error: {}, message: "Cannot read property 'attrs' of undefined" }, ], [ { descriptions: { attrs: { lang: "sp", }, }, }, { descriptions: { attrs: { lang: "en-GB", }, }, }, { descriptions: { attrs: { lang: "it", }, }, }, ], [ { descriptions: { attrs: { lang: "en", }, }, }, { descriptions: { attrs: { lang: "uk", }, }, }, { descriptions: { attrs: { lang: "en-GB", }, }, }, ], ];

Filtro Js: esto solo funciona cuando conozco los mensajes

 let objectToBeRemove = [{ error: {}, message: "Cannot read property 'attrs' of undefined" }]; filtData = filtData.filter((obj) => objectToBeRemove.some((objToRemove) => JSON.stringify(objToRemove) !== JSON.stringify(obj)));
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Verifique que cada uno de los elementos en el .every carezca de una propiedad de error .

 const input=[[{descriptions:{attrs:{lang:"en-GB"}}},{descriptions:{attrs:{lang:"es"}}},{error:{},message:"Cannot read property 'attrs' of undefined"}],[{descriptions:{attrs:{lang:"sp"}}},{descriptions:{attrs:{lang:"en-GB"}}},{descriptions:{attrs:{lang:"it"}}}],[{descriptions:{attrs:{lang:"en"}}},{descriptions:{attrs:{lang:"uk"}}},{descriptions:{attrs:{lang:"en-GB"}}}]]; const filtered = input.filter( subarr => subarr.every(obj => !obj.hasOwnProperty('error')) ); console.log(filtered);

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!