Skip to content

sample ​

从数组中获取一个随机元素。

示例 ​

ts
import { sample } from '@base-web-kits/base-tools-ts';

sample([1, 2, 3, 4]);
// 结果: 2 (随机)

参数 ​

  • collection (Array): 要取样的集合。

返回值 ​

  • (any): 返回随机元素。

来源 ​