There is a very convenient function shuffle() in PHP for shuffling arrays. This function is used in many situations, but JavaScript arrays do not have this method. It doesn’t matter if you don’t have it. You can extend one. Do it yourself and you will have enough food and clothing. .
Please refresh the page to see the random sorting effect.
Output result:
shuffle(A) = 1,5,0,9,2,3,6,8,4,7
A.shuffle() = 0,4,2,8,5,1,3,6,9,7
Add a method to the array through prototype: