Map returns Empty statement array

I have this function

function getDaysArray(days: number): number[] {
        return [ Array(days)].map((_x, i) => {
            return i + 1;

which is supposed to return an array of days by month,
so for example If I log getDaysArray(31) I expect to have an array like this


but instead, I am getting this:

[empty × 31]

Does anyone know what is happening?

>Solution :

you can do something like this

function getDaysArray(days) {
        return Array.from({length: days}).map((_, i) => i + 1)



Leave a Reply