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

92
Views
cómo filtrar en función de dos valores de la matriz de matriz

Tengo una gran variedad de objetos con participantes y mensajes, quiero filtrar el objeto con la siguiente matriz de dos participantes, ¿alguien puede ayudar con esto?

este es el ejemplo de los participantes de la matriz:

["61badffe4ccf060b329441e0","61bc33a84ccf060b32944354"]

montón de mensajes de muestra y participantes:

 { "messages": [], "participants": [ "61badffe4ccf060b329441e0", "61bae01b4ccf060b329441ef" ], "_id": "61bae0394ccf060b329441fb", }, { "messages": [], "participants": [ "61bae1014ccf060b3294420e", "61bae01b4ccf060b329441ef" ], "_id": "61bb230c4ccf060b3294421c" }, { "messages": [], "participants": [ "61badffe4ccf060b329441e0", "61bc33a84ccf060b32944354" ], "_id": "61d476dff651471663a72971", }, { "messages": [], "participants": [ "61badffe4ccf060b329441e0", "61e54b82eab592e7fef65656" ], "_id": "61e54ba3eab592e7fef6567a", ] **expected below object after filter participants:** ```{ "messages": [], "participants": [ "61badffe4ccf060b329441e0", "61bc33a84ccf060b32944354" ], "_id": "61d476dff651471663a72971", },
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Es posible que desee usar Array.filter() y también en su caso, debe verificar cada elemento de esa matriz que coincida con sus criterios.

 const input = [{ "messages": [], "participants": [ "61badffe4ccf060b329441e0", "61bae01b4ccf060b329441ef" ], "_id": "61bae0394ccf060b329441fb", }, { "messages": [], "participants": [ "61bae1014ccf060b3294420e", "61bae01b4ccf060b329441ef" ], "_id": "61bb230c4ccf060b3294421c" }, { "messages": [], "participants": [ "61badffe4ccf060b329441e0", "61bc33a84ccf060b32944354" ], "_id": "61d476dff651471663a72971", }, { "messages": [], "participants": [ "61badffe4ccf060b329441e0", "61e54b82eab592e7fef65656" ], "_id": "61e54ba3eab592e7fef6567a", } ]; const filterByParticipants = ["61badffe4ccf060b329441e0","61bc33a84ccf060b32944354"]; const output = input.filter(el => el.participants.every(el => filterByParticipants.includes(el))); console.log(output);

about 4 years ago · Juan Pablo Isaza Report

0

Debe usar el método filter () de Array Object para filtrarlo según ciertas condiciones.
Luego puede usar el método every() de la matriz de participants para verificar si cada participante está presente en el objeto.

 let obj=[{messages:[],participants:["61badffe4ccf060b329441e0","61bae01b4ccf060b329441ef"],_id:"61bae0394ccf060b329441fb"},{messages:[],participants:["61bae1014ccf060b3294420e","61bae01b4ccf060b329441ef"],_id:"61bb230c4ccf060b3294421c"},{messages:[],participants:["61badffe4ccf060b329441e0","61bc33a84ccf060b32944354"],_id:"61d476dff651471663a72971"},{messages:[],participants:["61badffe4ccf060b329441e0","61e54b82eab592e7fef65656"],_id:"61e54ba3eab592e7fef6567a"}]; let participants =["61badffe4ccf060b329441e0","61bc33a84ccf060b32944354"]; let res = obj.filter((o)=>{ let oParticipants = o.participants; let out = participants.every(p => oParticipants.includes(p)) return out; }); console.log(res)

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!