The chosen answer will work well. However, this answer will run faster:
var randomProperty = function (obj) {
var keys = Object.keys(obj);
return obj[keys[ keys.length * Math.random() << 0]];
};
More Related Contents:
- What exactly does Math.floor do?
- how to use if(math.random == 50)? [closed]
- Do not include in random number
- Getting a random value from a JavaScript array
- Generate random string/characters in JavaScript
- Generate random number between two numbers in JavaScript
- Random color generator
- Seedable JavaScript random number generator
- How to randomize (shuffle) a JavaScript array?
- Generating random whole numbers in JavaScript in a specific range
- Random alpha-numeric string in JavaScript?
- math random number without repeating a previous number
- Generate unique number within range (0 – X), keeping a history to prevent duplicates
- Create an array with random values
- Sampling a random subset from an array
- Is Math.random() cryptographically secure?
- Generate random integers with probabilities
- Generating unique random numbers (integers) between 0 and ‘x’
- How to choose a weighted random array element in Javascript?
- Generate random password string with requirements in javascript
- Random floating point double in Inclusive Range
- How is randomness achieved with Math.random in javascript?
- Write a truly inclusive random method for javascript
- Random number generator without dupes in Javascript?
- Elegant method to generate array of random dates within two dates
- Collisions when generating UUIDs in JavaScript
- Javascript: Generate a random number within a range using crypto.getRandomValues
- Creating array of length n with random numbers in JavaScript
- Random Point on a given Sphere
- JavaScript – How to randomly sample items without replacement?