Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

134
Visualizações
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 Respostas
Responde à pergunta

0

Using Array#filter:

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

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda