Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

283
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!