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

135
Vistas
Delete the object in place from an array: JS

I am having an array of objects with the following structure:

const timeOptions = [
  { key: "all", value: "all", text: "All" },
  { key: "month", value: "month", text: "Month" },
  { key: "year", value: "year", text: "Year" }
];

I am creating a new object with this timeOptions being a value of a field in it. How to remove the object with key "all" in-place while creating the object itself

const values = {
  timeVal: {
    field: "timestamp",
    label: "Timestamp",
    options: timeOptions
  }
};

Code that I tried


const values = {
  timeVal: {
    field: "timestamp",
    label: "Timestamp",
    options: timeOptions.forEach((k) => delete k["key"] === "all")
  }
};
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Using Array#filter:

options: timeOptions.filter(({ key }) => key !== 'all')
about 4 years ago · Juan Pablo Isaza Denunciar

0

If I understand you correctly, you need filter

const values = {
 timeVal: {
 field: "timestamp",
 label: "Timestamp",
 options: timeOptions.filter((k) =>  k["key"] !== "all")
}

};

This will copy all except the one with key "all"

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