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

180
Views
how can i check if an array of objects contains a key which is in array of strings js?

We have an array of objects like

const arr = [{id: "someId", name: {...}}, ...];
const skippedKeys = ["id"...]

How can i filtered the array of object based on skipped keys? The result should be:

const result = [{name: {...}}, ...];

Also i don't want to make a cycle inside the cycle. the result also could be implemented using lodash library. we should remove key with value as well.

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

0

Since you stated that it could be implemented using lodash, here is some code using lodash:

let result = _.map(arr, (el)=> _.omit(el, skippedKeys))

about 4 years ago · Juan Pablo Isaza Report

0

It's simple and no need for any nested cycles. There are two option to do that

  1. Using includes function
    const result = arr.filter((item) => !result.includes(item.id));
  1. Using set
    const dataSet = new Set(skippedKeys);
    const result = arr.filter((item) => !dataSet.has(item.id));

I prefer the second one as it excludes double checks. Hope the answer was helpful.

about 4 years ago · Juan Pablo Isaza Report

0

const result = arr.map(obj =>
  Object.keys(obj).reduce(
    (res, key) => (
      skippedKeys.includes(key) ? res : {...res, [key]: obj[key]}
    ),
    {},
));
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!