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

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

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 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