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

160
Views
Usando una matriz de objetos, cree una nueva matriz que contenga todos los objetos de la matriz original de objetos que tengan un valor numérico mayor que 15

ayuda, por favor, tengo esta matriz de objetos y debo crear una nueva matriz que contenga todos los objetos de la matriz original de objetos que tienen un valor numérico superior a 15. ¿Cómo puedo hacer esto? ¿Qué método hay que usar?

 const names = [ { name: 'Anna' }, { num: 27 }, { name: 'Valeria', age: 20}, { secondname: 'Wilson' }, { age: 12, name: 'Max' }, { weight:'50kg', height: '172cm', name: 'Nick' } ]

trato de usar el filtro, pero debería ver cualquier campo que tenga un valor numérico, no solo la edad o el número

 const number = arr.filter(a => a.num || a.age > 15); console.log(number);
about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

Si desea obtener solo números, debe verificar los valores del objeto con Array#some y typeof operator .

 const names = [{ name: 'Anna' }, { num: 27 }, { name: 'Valeria', age: 20 }, { secondname: 'Wilson' }, { age: 12, name: 'Max' }, { weight: '50kg', height: '172cm', name: 'Nick' }], result = names.filter(o => Object .values(o) .some(v => typeof v === 'number' && v > 15) ); console.log(result);
 .as-console-wrapper { max-height: 100% !important; top: 0; }

about 4 years ago · Santiago Gelvez 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!