This time I will bring you JS random sorting array, what are the precautions for JS randomly sorting array, the following is a practical case, let's take a look.
The example in this article describes the method of JS generating randomly scrambled arrays. Share it with everyone for your reference, the details are as follows:
1. A messy sorting method
function fnLuanXu(num) { var aLuanXu=[]; for (var i = 0; i <p style="text-align: left;"> operation result:</p><p style="text-align: left;"> <img src="http://img./attachment/art/153853/f17c3f78cb.png?20171123142429" alt="JS randomly sort array"></p><p style="max-width:90%"> <strong>2. A less messy sorting method, js<a href="http://www.php.cn/wiki/157.html" target="_blank">built-in function</a>. </strong></p><pre class="brush:php;toolbar:false">function fnLuanXu(num) { var aLuanXu=[]; for (var i = 0; i 0.5?-1:1;}) return aLuanXu; } //测试: console.log(fnLuanXu(7));
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading:
Use fastclick source code to parse tap
The above is the detailed content of JS randomly sort array. For more information, please follow other related articles on the PHP Chinese website!