-4

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

Xwingoga06
  • 99
  • 1
  • 10
  • 4
    `Array.from({ length: 10 }, (_, i) => i + 1)` – ray Nov 21 '22 at 14:59
  • 1
    Please visit the [help], take the [tour] to see what and [ask]. If you get stuck, post a [mcve] of your attempt, noting input and expected output using the [\[<>\]](https://meta.stackoverflow.com/questions/358992/ive-been-told-to-create-a-runnable-example-with-stack-snippets-how-do-i-do) snippet editor. – mplungjan Nov 21 '22 at 15:02
  • Also a massive dupe – mplungjan Nov 21 '22 at 15:03

2 Answers2

2

const arr = Array.from({ length: 10 }, (_, i) => i + 1);
console.log(arr);
ray
  • 26,557
  • 5
  • 28
  • 27
-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))

Abbas Shaikh
  • 304
  • 1
  • 9