Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda