Course lesson

Find a Random Element in a JSON File in Node.js

Currently we are grabbing the first element in the array that our JSON data gives us back. We want a random element (or question) from our file.

Duration
1 min
Access
Included
Transcript
Retained from source evidence

Currently we are grabbing the first element in the array that our JSON data gives us back. We want a random element (or question) from our file.

To get a random element from an array we will use Math.Floor and Math.Random in combination with the array length to get a random question returned to us.