Home >Web Front-end >JS Tutorial >JavaScript arrays are randomly arranged to implement random shuffling function_javascript skills
The example in this article describes the method of randomly arranging JavaScript arrays to implement random shuffling function. Share it with everyone for your reference. The specific analysis is as follows:
This JS code can randomly arrange the elements in the array. This is very useful. For example, when we play poker, we can arrange the poker cards, which is the computer shuffling the cards.
var list = [1,2,3,4,5,6,7,8,9]; list = list.sort(function() Math.random() - 0.5); Print(list); // prints something like: 4,3,1,2,9,5,6,7,8
I hope this article will be helpful to everyone’s JavaScript programming design.