Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

178
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda