Reputation: 1374
I'm receiving a bit of a strange error.
I'm trying to select the index of an array at random, so to do this I am using the code below:
myArray[Math.floor(Math.random*myArray.length)]
myArray.length is 282, but Math.floor(Math.random*myArray.length)
is NaN and myArray[Math.floor(Math.random*myArray.length)
is undefined.
Any thoughts?
Upvotes: 2
Views: 1753
Reputation: 4358
Math.random() and Math.random(), go through API links.
Your code will be:
myArray[Math.floor(Math.random()*myArray.length)]
Upvotes: -1
Reputation: 388316
Math.random
is a function it should be Math.random()
Try
myArray[Math.floor(Math.random()*myArray.length)]
Upvotes: 9