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

141
Views
How exactly does "Object.values.filter(Boolean)" work in JavaScript?

I was reading a code saw the following line of the code and am just wondering to know how does this line of code work:

    const roles = Object.values(foundUser.roles).filter(Boolean);

If this is the User Schema:

const userSchema = new Schema({
    email: {
        type: String,
        required: true,
        unique: true
    },
    username: {
        type: String,
        // required: true,
        unique: true
    },
    password: {
        type: String,
        required: true
    },
    roles: {
        User: {
            type: Number,
            default: 2001
        },
        Editor: Number,
        Admin: Number
    },
    refreshToken: [String]
});

I can't understand what does the filter(Boolean) function do? What does Boolean as input mean? What goes to the filter() and what comes out from it?

EDIT: For example if we have a User object that has the default value of roles: {User: {type: Number, default: 2001} , Editor: undefined , Admin: undefined} what would be the value of const roles? [2001] or [User]?

about 4 years ago · Juan Pablo Isaza
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!