Languages
[Edit]
EN

JavaScript - sort in random order

7 points
Created by:
telsa
502

In this short article, we would like to show how to sort array items in random order in JavaScript.

Quick solution:

Warning: Array sort() method changes input array items order. 

 

Reusable function

Edit

 

Fisher–Yates shuffle algorithm

Edit

The below example implements Fisher–Yates shuffle algorithm:

 

References

Edit
  1. Fisher–Yates shuffle - Wikipedia

Alternative titles

  1. JavaScript - random array order
  2. JavaScript - shuffle array
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

JavaScript - random

Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join