Quiero dejar que el número aleatorio de matrices se actualice, pero no funcionó. ¿Alguien puede darme algún consejo?
var places=Array(50).fill({}).map( function(obj){ return { r: Math.random()*200, deg: Math.random()*360, opacity: 0 } } );Si está intentando crear una matriz de objetos con valores aleatorios, puede hacerlo:
El método de ciclo while normal :
// 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++ }El método Array.from :
// 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 } })