# 随机化数组元素的顺序

# 语法

import { shuffleArr } from 'jtoolset'
const result = shuffleArr(arr)

# 参数

  • arr (Array) : 需要打乱顺序的数组。

# 返回值

Array : 打乱顺序后的数组。

# 源码

const shuffleArr = (arr) => arr.sort(() => Math.random() - 0.5);

# 例子

import { shuffleArr } from 'jtoolset'
const ages = [1,2,3,4,5,6,7,8]
const result = shuffleArr(ages)
console.log(result) //=> [1, 7, 2, 3, 8, 4, 5, 6]