Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript pick random attribute from object

const animals = {
  'cat': 'meow',
  'dog': 'woof',
  'cow': 'moo',
  'sheep': 'baaah',
  'bird': 'tweet'
};

const keys = Object.keys(animals)
const prop = keys[Math.floor(Math.random() * keys.length)]
console.log(prop);
Source by thewebdev.info #
 
PREVIOUS NEXT
Tagged: #javascript #pick #random #attribute #object
ADD COMMENT
Topic
Name
8+3 =