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

107
Vistas
Leave objects by the list of keys. Pure JS

I want to create a new array of objects without the gender field. Where is the mistake?

let collections = [
    { name: "Tom", gender: "male", age: 12 },
    { name: "Becky", gender: "female", age: 11 },
    { name: "Huck", gender: "male", age: 13 }
  ];
  let newCollections = collections.slice();
  let operations = {
    select: function () {
      let args = [].slice.call(arguments);
      for (let i = 0; i < newCollections.length; i++) {
        for (let key in newCollections[i]) {
          for (let j = 0; j < args.length; j++) {
            if (key !== args[j]) {
              delete key;
              return newCollections;
            } } } } } }; 
const result = operations.select("name", "age");// the list of fields to save

console.log(result);

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can do it using map method:

const array_without_gender = collections.map(el => {
    return {name: el.name, age: el.age};
})

This code will create new array filled by objects without gender key,

about 4 years ago · Juan Pablo Isaza Denunciar

0

You could create an omit() function that will return an object without a given property.

We can then use Array.map() to run each item in the array through this:

let collections = [ { name: "Tom", gender: "male", age: 12 }, { name: "Becky", gender: "female", age: 11 }, { name: "Huck", gender: "male", age: 13 } ];

function omit(obj, field) {
    return (({ [field]: _, ...result }) => result)(obj);
}

let newCollections = collections.map(person => omit(person, 'gender'));
console.log('New collections:', newCollections);
.as-console-wrapper { max-height: 100% !important; top: 0; }

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