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

164
Views
Using array of object create a new array that contains all the objects from the original array of object that have a numerical value greater than 15

help please, i have this array of object and must to create a new array that contains all the objects from the original array of object that have a numerical value greater than 15. how can i do this ? which method a must to use ?

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

i try to use filter,but it should see any field that has a number value not just age or num

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

0

If you like to get only numbers, you chould check the values of the object with Array#some and 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!