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

110
Views
Return entire object not just key in js with filter

I currently have some data in a firebase db that contains multiple members like so:

membersData: {
    uid1: {
        first: 'blah'
        last: 'blah'
        mStatus: true
    }
    uid2: {
        first: 'blah'
        last: 'blah'
        mStatus: true
    }
    uid3: {
        first: 'blah'
        last: 'blah'
        mStatus: false
    }
}

To filter over my data I run this:

Object.keys(membersData).filter(member => membersData[member].mStatus == true)

However this only returns an array of the uid. How can I get it to return the uid but also the first, last and mStatus?

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

0

It returns the keys, because you are running from Object.keys.

Try running with Object.values to return the values you want:

Object.values(membersData).filter(member => member.mStatus == true);

about 4 years ago · Juan Pablo Isaza Report

0

You are getting only the keys with Object.keys. All the further computations are done on that array of keys. You can use a .map() again to get the items in the requested format.

You might simply use a different method like Object.values() if you are only concerned about the values and not the keys:

let membersData = {
    'uid1' : {
        'first': 'blah',
        'last': 'blah',
       'mStatus': true
    },
    'uid2': {
        'first': 'blah',
        'last': 'blah',
        'mStatus': true
    },
    'uid3': {
        'first': 'blah',
        'last': 'blah',
        'mStatus': false
    }
}

let ans = Object.keys(membersData).filter(member => membersData[member].mStatus == true).map(x => { return { [x] : membersData[x]} } );

console.log(ans);

let ans2 = Object.values(membersData).filter(member => member.mStatus == true);
console.log(ans2);

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!