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

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

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