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

118
Views
How to splice multiple values from array of objects which matches given nested array

I am trying to remove the array of objects if the given array of objects matches with the index but it is only removing the last index value.

How we can remove multiple values?

let idArr = [[{ index: 2 }], [{ index: 3 }]];

let obj = [
  {
    id: 1,
    name: 'abc',
  },
  {
    id: 2,
    name: 'abc',
  },
  {
    id: 3,
    name: 'abc',
  },
  {
    id: 4,
    name: 'abc',
  },
];
let data = obj.filter((item, i) =>
  idArr.reduce((val) => val.find(({ index }) => i === index))
);

//expected output

[
  {
    id: 1,
    name: 'abc',
  },
  {
    id: 2,
    name: 'abc',
  },
];

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

0

I think that following code achieves what you're expecting

let data = obj.filter((obj, idx) => !idArr.find(id => id[0].index === idx));
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!