I have following JavaScript array:
[
{
"day": 0,
"best_hour_of_the_day": "10",
"appt_success_rate": "60",
"appt_100_numbers": "27"
},
{
"day": 2,
"best_hour_of_the_day": "10",
"appt_success_rate": "60",
"appt_100_numbers": "27"
},
{
"day": 3,
"best_hour_of_the_day": "10",
"appt_success_rate": "60",
"appt_100_numbers": "27"
},
{
"day": 4,
"best_hour_of_the_day": "10",
"appt_success_rate": "60",
"appt_100_numbers": "27"
},
{
"day": 6,
"best_hour_of_the_day": "--",
"appt_success_rate": "0",
"appt_100_numbers": "0"
}
]
And I have defined array with with representation of the days which i need in result.
var daysOfTheWeek = [0,1,2,3,4,5,6];
I would like to ask, what is the good way how to add missing items to JavaScript array?
It means add missing values 1 and 6 to get following JavaScript result:
[
{
"day": 0,
"best_hour_of_the_day": "10",
"appt_success_rate": "60",
"appt_100_numbers": "27"
},
{
"day": 1,
"best_hour_of_the_day": "--",
"appt_success_rate": "0",
"appt_100_numbers": "0"
},
{
"day": 2,
"best_hour_of_the_day": "10",
"appt_success_rate": "60",
"appt_100_numbers": "27"
},
{
"day": 3,
"best_hour_of_the_day": "10",
"appt_success_rate": "60",
"appt_100_numbers": "27"
},
{
"day": 4,
"best_hour_of_the_day": "10",
"appt_success_rate": "60",
"appt_100_numbers": "27"
},
{
"day": 5,
"best_hour_of_the_day": "10",
"appt_success_rate": "60",
"appt_100_numbers": "27"
},
{
"day": 6,
"best_hour_of_the_day": "--",
"appt_success_rate": "0",
"appt_100_numbers": "0"
}
]
javascriptday: 5in the first example and afterday: 6in the second example are not valid syntax.