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

284
Visualizações
How can I delete some values in an array

I am new to js and struggle with objects and arrays within them. I got months and days in an event-object events[month] = {dates: []} like this:

events: (2) […]
5: {…}
​​​dates: (9) […]
0: 5
​​​1: 12
​​​​2: 19
​​​​3: 26
​​​​4: 3
​​​​5: 10
​​​​6: 17
​​​​7: 24
​​​​8: 31
​​​​length: 9
​​​​<prototype>: []
​​​<prototype>: {…}
​​6: {…}
​​​dates: (9) […]
​​​​0: 2
​​​​1: 9
​​​​2: 16
​​​​3: 23
​​​​4: 30
​​​​5: 7
​​​​6: 14
​​​​7: 21
​​​​8: 28
​​​​length: 9
​​​​<prototype>: []
​​​<prototype>: {…}

And now I want to delete several dates:

month: 5, day: 24, 26
month: 6, day: 14, 16

Do I have to make several loops to get this done? I tried some for() and if() statements, but somehow the logic is tricky. Are there other methods to do this? You help is greatly appreciated.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use recursion for this if you don't know nesting of objects. In your case you have to use forEach method to find needful elements. But remember to not to mutate starting array.

const newEvents = events;
events.forEach((item, i) => {
  if (i === 5) {
    item.dates.forEach((innerItem, j) => {
      if (innerItem === 24) newEvents.splice(j, 1);
    })
  }
})
return newEvents;
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