Now I have an array like below.
const reserveList = [
{ name: 'john', start: '2022-09-01' },
{ name: 'mark', start: '2022-09-02' },
{ name: 'ken', start: '2022-09-03' },
{ name: 'sara', start: '2022-09-05' },
];
and I want to add empty object if there is empty day between two days like below.
const reserveList = [
{ name: 'john', start: '2022-09-01' },
{ name: 'mark', start: '2022-09-02' },
{ name: 'ken', start: '2022-09-03' },
{},
{ name: 'sara', start: '2022-09-05' },
];
here is my code(it doesn't work). Is it possible to make it work using map
or other ways?
const newList = (reserveList: Array<any>) => {
reserveList.map((reserve, index) => {
dayjs(reserveList[index + 1].start).diff(
dayjs(reserveList[index].start, 'day') > 1
) && reserveList.splice(index + 1, 0, {});
});
};