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

84
Views
Filtering an array based off of another objects values

I'd like to filter this programs array (I've simplified the objects):

const programs = [
      {
        format: "In-Person",
        schedule: "Full-Time",
      },
      {
        format: "Remote",
        schedule: "Full-Time",
      },
      {
        format: "In-Person",
        schedule: "Part-Time",
      },
      {
        format: "Remote",
        schedule: "Part-Time",
      }
    ]

based on a filter object:

const filters = {format: "Remote", schedule:"Full-Time"}

My attempt:

  let filteredPrograms = programs.filter((program) => {
    return Object.entries(filters).every(([key, value]) => {
      program[key] == value;
    });
  });

This should analyze each program, and allow is to pass through the filter IF: For every filter key, the program[filter key] value matches the filter value

But I'm getting an empty array for filteredPrograms

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

0

Return the comparison result inside the every callback:

const programs=[{format:"In-Person",schedule:"Full-Time"},{format:"Remote",schedule:"Full-Time"},{format:"In-Person",schedule:"Part-Time"},{format:"Remote",schedule:"Part-Time"}],filters={format:"Remote",schedule:"Full-Time"};

let filteredPrograms = programs.filter((program) => {
  return Object.entries(filters).every(([key, value]) => {
    return program[key] == value;
  });
});
console.log(filteredPrograms)

Or make it an arrow function:

const programs=[{format:"In-Person",schedule:"Full-Time"},{format:"Remote",schedule:"Full-Time"},{format:"In-Person",schedule:"Part-Time"},{format:"Remote",schedule:"Part-Time"}],filters={format:"Remote",schedule:"Full-Time"};

let filteredPrograms = programs.filter((program) => {
  return Object.entries(filters).every(([key, value]) => program[key] == value);
});
console.log(filteredPrograms)

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!