Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Map returns Empty statement array

I have this function

function getDaysArray(days: number): number[] {
        return [...new 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

[1,2,...,31]

but instead, I am getting this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

}

console.log(getDaysArray(31))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading