Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

182
Views
Generate numbers from 1 to 100 in an array in a way no number is repeated

How do I generate numbers from 1 to 100 in an array without actually typing every single number from 1 to 100 in a way that each number appears only once. I later need to move the generated numbers to an different array but I have that part figured out. Here is what I have done so far

const arr1 = [1,2,3,4,5,6]
const arr2 = []

const ran = () => {
  const index = Math.floor(Math.random() * arr1.length);
  if(arr1.length>0)
  {
    arr2.push(arr1[index])
    arr1.splice(index, 1)
    
    const display = document.getElementById('array')
    display.innerText = ("\nArray 2 elements " + arr2.toString() + "\n Remaining Array 1 elements" + arr1.toString())
  }
  else
    {
      document.write("Array is now empty");
    }
}
<button onClick=ran()>click</button>
<span id='array' />

In the above snippet I have displayed elements in array1 as well but I don't need to do it if the numbers are from 1 to 100

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you can use map

const array = Array(100).fill(1).map((n, i) => n + i)

console.log(array)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!