js/typescript: get random object in an array

const animals = [
  {sort: 'dog'},
  {sort: 'cat'},
  {sort: 'tiger'}
]

to get a random one animal:

let animal = animals[Math.floor(Math.random() * animals.length)];
添加评论
取消
*
*
*
*
勇士!消灭0条评论,这么艰巨的任务就靠你了!