Skip to content
Advertisement

Missing months in Calendar

I am trying to set values of any missing months in my nested array for specific years.

Data:

JavaScript

As you can see in the above array, year 2019 and 2018 have missing months. How can I can add those missing months and set the values to zero? Please advice.

Advertisement

Answer

Use array_replace() to overlay one array with another.

JavaScript

If there is a key present in data, then its value is used, otherwise the value from months is used.

Teh Playground

Code for months array (apHarmony)

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement