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

242
Views
Divida la matriz de objetos en 2 matrices de elementos coincidentes y no coincidentes
const users = [ { _id: "5fbfa729fc46a415ce5503a6", first_name: 'Allen', last_name: 'Border', timestamp: 1606395689121, key: [ "5fbf6f91aff7f3320a906547", "5fbfa748fc46a415ce5503a8" ] }, { _id: "5fbfa6fbfc46a415ce5503a4", first_name: 'james', last_name: 'roger', timestamp: 1606395689125 }, { _id: "5fbf6f91aff7f3320a906547", first_name: 'david', last_name: 'gosh', timestamp: 1606395689130, key: [ "5fbfa729fc46a415ce5503a6" ] }, { _id: "5e4e74eb380054797d9db623", first_name: 'Ricky', last_name: 'bichel', timestamp: 1606395689131 } ] const user_id = "5fbfa748fc46a415ce5503a8";

cómo separar los datos que no coinciden si user_id coincide con users.key, debería tener datos coincidentes que no coincidan, debería tener datos notMatch. ¿Podemos separar dos resultados que coinciden y no coinciden con los registros?

No funciona

 const result = users.key.indexOf(user_id); console.log(users.storyMute)
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede usar Array.prototype.reduce() de la siguiente manera:

 const users=[{_id:"5fbfa729fc46a415ce5503a6",first_name:"Allen",last_name:"Border",timestamp:1606395689121,key:["5fbf6f91aff7f3320a906547","5fbfa748fc46a415ce5503a8"]},{_id:"5fbfa6fbfc46a415ce5503a4",first_name:"james",last_name:"roger",timestamp:1606395689125},{_id:"5fbf6f91aff7f3320a906547",first_name:"david",last_name:"gosh",timestamp:1606395689130,key:["5fbfa729fc46a415ce5503a6"]},{_id:"5e4e74eb380054797d9db623",first_name:"Ricky",last_name:"bichel",timestamp:1606395689131}] const user_id="5fbfa748fc46a415ce5503a8" const {matching, nonMatching} = users.reduce((acc, userRecord) => { userRecord?.key?.includes(user_id) // or, if you need to compare by _id // userRecord._id === user_id ? acc.matching.push(userRecord) : acc.nonMatching.push(userRecord) return acc }, {matching: [], nonMatching: []}) console.log(matching)

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!