如何从数组中随机取出几个值组成新的数组?

方法一

使用lodash 的 sampleSize 方法

  • _.sampleSize(collection, [n=1])
  • 定义:Gets n random elements at unique keys from collection up to the size of collection.


	<span class="hljs-built_in">test</span>
	





复制代码

你可能感兴趣的:(如何从数组中随机取出几个值组成新的数组?)