Home > Web Front-end > JS Tutorial > body text

JS randomly sort array

php中世界最好的语言
Release: 2018-04-13 17:08:18
Original
1567 people have browsed it

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="//m.sbmmt.com/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));
Copy after login

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:

How to use JSONAPI in PHP

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!