12
I need to create an array that is filled with the values of 0 a n
, as if using the function range(n)
, Python3, but using Javascript features.
I thought I’d create a function:
function generateRange(n){
let range = new Array(n);
range.forEach((x, index) => {
x = index+1;
})
return range;
}
But I found this way too laborious, and perhaps unnecessary. There is a simpler way to treat this data and generate the same result?
Arthur, this method of yours, in my opinion, is very clean, easy to understand, however much I make a different code for you, it is possible that you do not think it better than yours, so your question is based on opinion.
– Renan