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

194
Views
fill remaining indexes in array with null values

I need to adjust for blank days in my calendar app. There should be 35 blocks to make up the calendar, but I need to fill the array with 30 items inside of that. Is there a method that allows that?

so far this just pushes the days, but you will notice the last days stretch. How can I get blank days in my array? I think i need ensure the calendar is always 35 items.

So I want [null, null, 0, 1, 2, 3, 4, 5...last day in month]. almost like flex end.

Example:

var monthIndex = 0;
var calendarDays = [];
var daysInMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31];


 function updateCalendar() {
      calendarDays = [];
      for (let i = 0; i < daysInMonth[monthIndex]; i++) {
        calendarDays.push(i);
      }
 },

enter image description here

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use #Array.fill and then map in the values, like

new Array(35).fill(" ").map((_, i) => i <= daysInMonth[monthIndex] ? i : '')

var calendarDays = [];
var daysInMonth = [31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31];


function updateCalendar(monthIndex) {
  calendarDays = new Array(35).fill(" ").map((_, i) => i <= daysInMonth[monthIndex] ? i : '');
  return calendarDays;
}

console.log(updateCalendar(0))
console.log(updateCalendar(1))

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!