Creating array of length n with random numbers in JavaScript
问题 Following up on this answer for creating an array of specified length, I executed the below to get a corresponding result but filled with random numbers, instead of zeros. var randoms = Array(4).fill(Math.floor(Math.random() * 9)); Well, mathematically speaking it's random , all right. But I'd like the randomness to be visible within the array and not only between runs, of course. Stupid computer... Don't do what I say. Do what I want! I can iterate and put it my random (and varying) values.