UNPKG

random-array-index

Version:

Get the random index of an array

12 lines (8 loc) 261 B
'use strict' var isArrayLike = require('is-array-like') module.exports = function randomArrayIndex (arr) { if (!isArrayLike(arr)) { throw TypeError('Expected argument to be an array or array-like') } return Math.floor(Math.random() * arr.length) }