Create an Array given one number

I code a js script with for but now I need to move it to react and I need to create an array with the position of the number of state. Example: NumberState = 3 | I need to create an array like this [1, 2,3] or NumberState = 7 | I need [1,2,3,4,5,6,7] I need to do a map and render a component with the value
2 Replies
MarkBoots
MarkBoots13mo ago
const numberState = 3
const array = Array.from({length: numberState}, (_, i) => i + 1 )
console.log(array) // [1,2,3]
const numberState = 3
const array = Array.from({length: numberState}, (_, i) => i + 1 )
console.log(array) // [1,2,3]
s.XXI Investor
s.XXI InvestorOP13mo ago
Thanks a lot!
Want results from more Discord servers?
Add your server