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

Share this video with your friends

Send Tweet

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.