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

142
Views
Filtering array inside object

I need to filter an array inside the object and return a new array that matches the filter

const example = [ { id: 1, b: [1, 2]}, {id:2, b:[1]}, {id 3, b: [1,3]}
const filter = 1

the return of the filter should just be [{id: 2, b:[1]}]

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

0

1) If you only want an object that only contain 1 inside it. then you can it using filter do as:

o.b.length === 1 && o.b[0] === filter

const example = [
  { id: 1, b: [1, 2] },
  { id: 2, b: [1] },
  { id: 3, b: [1, 3] },
];
const filter = 1;

const result = example.filter((o) => o.b.length === 1 && o.b[0] === filter);
console.log(result);

2) Using includes and filter

const example = [
  { id: 1, b: [1, 2] },
  { id: 2, b: [1] },
  { id: 3, b: [1, 3] },
];
const filter = 1;

const result = example.filter((o) => o.b.length === 1 && o.b.includes(filter));
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!