Skip to content

sample

js
_.sample(collection)

collection 获取一个随机元素。

¥Gets a random element from collection.

新增于

¥Since

2.0.0

参数

¥Arguments

  1. collection (数组|对象):要采样的集合。

    ¥collection (Array|Object): The collection to sample.

返回

¥Returns

(*):返回随机元素。

¥()*: Returns the random element.

示例

¥Example

js
_.sample([1, 2, 3, 4]);
// => 2

Lodash v4.17 中文网 - 粤ICP备13048890号