ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
## sampleSize + [link](./sampleSize "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L8128 "View in source.") + [npm](https://www.npmjs.com/package/lodash.samplesize "See the npm package.") ``` _.sampleSize(collection, [n=0]) ``` 获得从集合中随机获得 `N` 个元素 Gets `n` random elements from `collection`. ### 参数 1. collection (Array|Object) 要取样的集合 2. [n=0] (number) 要取得的元素个数 ### 返回值 (Array) 返回随机元素 ### 示例 ``` _.sampleSize([1, 2, 3], 2); // => [3, 1] _.sampleSize([1, 2, 3], 4); // => [2, 3, 1] ```