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

138
Views
How to filter object based on conditional argument?

I am calling a function with two arguments,

Arg 1: Object {a:1, b:2, c:3, d:4}

Arg 2: Condition ((prop, key) => prop >= 3))

Here based on the condition we need to filter the object and provide the result as array of objects.

The code that I have tried,

const pickBy = (a, b) => {
  const data = Object.values(a).filter(b);
  console.log(data)
}

pickBy({a:1, b:2, c:3, d:4}, ((prop, key) => prop >= 3))

Current Result: [3,4]

Expected Result: [{c:3}, {d:4}]

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You could get the entries, filter by handing over the right format for filtering function and build objects of filtered entries.

const
    pickBy = (object, filterFn) => Object
        .entries(object)
        .filter(([k, v]) => filterFn(v, k))
        .map(([k, v]) => ({ [k]: v }));

console.log(pickBy({ a: 1, b: 2, c: 3, d: 4 }, (prop, key) => prop >= 3));

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!