How to shuffle an array of objects in javascript?

后端 未结 3 507
忘掉有多难
忘掉有多难 2021-01-05 12:45

The code below works for a normal array but not with an array with object does anybody knows how to do this?

3条回答
  •  北海茫月
    2021-01-05 13:11

    Here is one more example based on lodash _.shuffle.

    const array = [
        { some: 1 },
        { some: 2 },
        { some: 3 },
        { some: 4 },
        { some: 5 },
        { some: 6 },
        { some: 7 },
      ];
    console.log(_.shuffle(array));

提交回复
热议问题