skip to Main Content

I have a maximum of quantity on a value and i want to see all the number on my dropdown

for exemple my quantity is

const quantity= 10

i want to create a function which pushed [1,2,3,4,5,6,7,8,9,10] on an array.

I’m working with react native

2

Answers


  1. This will help you

    
        function createArray(len){
          let arr = [] 
          for(let i = 0 ; i < len;i++){
            arr.push(i + 1);
          }
          return arr
        }
        
        let qty = 10
        console.log(createArray(qty))
    
    
    Login or Signup to reply.
  2. const arr = Array.from({ length: 10 }, (_, i) => i + 1);
    console.log(arr);
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search