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

149
Views
The random number of array

I want let the random number of array keep refresh,but it didn't work. Can someone give me some advice?

var places=Array(50).fill({}).map(
  function(obj){
    return {
      r: Math.random()*200,
      deg: Math.random()*360,
      opacity: 0
    } 
  }
);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

If you are trying to create array of objects with random values, you can do it:

The normal while loop method:

// declare empty array for later use
const places = []

// iterate 50 times, for each iteration, 
// create and add one object with random values into array
let i = 0
while(i < 50) {
    places.push({
      r: Math.random() * 200,
      deg: Math.random() * 360,
      opacity: 0
  })
  
  i++
}

The Array.from method:

// first argument define the length of array
// second argument define function to execute for every iteration
const places = Array.from({length: 50}, () => {
 return {
    r: Math.random() * 200,
    deg: Math.random() * 360,
    opacity: 0
  }
})
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!