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

153
Views
filter array includes multiple items

i want to filter an array by some specific names

genres = [
{id: 1, name: 'Action'},
{id: 2, name: 'Comedy'},
{id: 3, name: 'Documentary'},
{id: 4, name: 'Action'},
{id: 5, name: 'Comedy'},
]

// in here i get only Action
genres.filter(i => i.name.includes("Action"))
output = [
{id: 1, name: 'Action'},
{id: 4, name: 'Action'},
]

// in here i get only Comedy
genres.filter(i => i.name.includes("Comedy"))
output = [
{id: 2, name: 'Comedy'},
{id: 5, name: 'Comedy'},
]

But i want to get both Action and Comedy like this:

[
{id: 1, name: 'Action'},
{id: 4, name: 'Action'},
{id: 2, name: 'Comedy'},
{id: 5, name: 'Comedy'},
]

How can i do it?

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

0

genres.filter(i => i.name.includes("Action") | i.name.includes("Comedy"))

or

genres.filter(i => ["Action","Comedy"].includes(i.name))

about 4 years ago · Juan Pablo Isaza Report

0

Use an OR operator to check on both conditions

genres = [
{id: 1, name: 'Action'},
{id: 2, name: 'Comedy'},
{id: 3, name: 'Documentary'},
{id: 4, name: 'Action'},
{id: 5, name: 'Comedy'},
]

// Use a OR operator to check both conditions
result = genres.filter(i => i.name.includes("Action") || i.name.includes("Comedy"))


console.log(result)

about 4 years ago · Juan Pablo Isaza Report

0

You can do:

const genres = [{id: 1, name: 'Action'},{id: 2, name: 'Comedy'},{id: 3, name: 'Documentary'},{id: 4, name: 'Action'},{id: 5, name: 'Comedy'},]

const result = genres.filter(({ name }) => ['Action', 'Comedy'].includes(name))

console.log(result)

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!