欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

JavaScript数组乱序排序

程序员文章站 2022-04-15 23:07:58
1.对数组打乱顺序 <div class="content"> <p> 1.对数组打乱顺序 </p> <div class="cnblogs_code" onclick="cnblogs_code_show('6564dd25-764d-4659-966b-0276f9f0f301')"> <img onerror="this.src='/statics/superweb999/images/image_error.jpg'"src="/default/index/img?u=aHR0cDovL2ltYWdlcy4xMHFpYW53YW4uY29tLzEwcWlhbndhbi8yMDE3MTIwOC9iXzFfMjAxNzEyMDgxOTUzMzY2NDY0LmpwZw==" alt="JavaScript数组乱序排序" title="JavaScript数组乱序排序"><img onerror="this.src='/statics/superweb999/images/image_error.jpg'"style="display:none;" src="/default/index/img?u=aHR0cDovL2ltYWdlcy4xMHFpYW53YW4uY29tLzEwcWlhbndhbi8yMDE3MTIwOC9iXzFfMjAxNzEyMDgxOTUzMzY5OTc3LmpwZw==" alt="JavaScript数组乱序排序" title="JavaScript数组乱序排序"><div id="cnblogs_code_open_6564dd25-764d-4659-966b-0276f9f0f301" class="cnblogs_code_hide"> <pre class="brush: javascript;"><!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>document</title> </head> <body> <script> var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; arr.sort(function (a, b) { return math.random() - 0.5; //使用随机数,大于0.5的往后排,小于0.5的往前排 }) console.log(arr); </script> </body> </html></pre> </div> </div> <p>  转自:https://www.cnblogs.com/lanshanxiao/p/12750799.html </p> </div> <div class="info-pre-next"> <p> 上一篇: <a href="/article/609942.html"> nginx+paas实现集成跨域和负载均衡 </a> </p> <p> 下一篇: <a href="/article/609944.html"> Java动态性之反射机制 </a> </p> </div> <div class="wz_tuijian"> <p> 推荐阅读 </p> <ul> <li> <a href="/article/2232070.html" target="_blank" title="JavaScript实现的冒泡排序法及统计相邻数交换次数示例"> <h2> JavaScript实现的冒泡排序法及统计相邻数交换次数示例 </h2> </a> </li> <li> <a href="/article/2228140.html" target="_blank" title="堆排序实例(Java数组实现)"> <h2> 堆排序实例(Java数组实现) </h2> </a> </li> <li> <a href="/article/2223653.html" target="_blank" title="C#实现对数组进行随机排序类实例"> <h2> C#实现对数组进行随机排序类实例 </h2> </a> </li> <li> <a href="/article/2220616.html" target="_blank" title="JavaScript中数组Array方法详解"> <h2> JavaScript中数组Array方法详解 </h2> </a> </li> <li> <a href="/article/2220611.html" target="_blank" title="JavaScript中数组Array.sort()排序方法详解"> <h2> JavaScript中数组Array.sort()排序方法详解 </h2> </a> </li> <li> <a href="/article/2220621.html" target="_blank" title="详解数组Array.sort()排序的方法"> <h2> 详解数组Array.sort()排序的方法 </h2> </a> </li> <li> <a href="/article/2220598.html" target="_blank" title="php二维数组排序方法(array_multisort usort)"> <h2> php二维数组排序方法(array_multisort usort) </h2> </a> </li> <li> <a href="/article/2220509.html" target="_blank" title="php对数组排序的简单实例"> <h2> php对数组排序的简单实例 </h2> </a> </li> <li> <a href="/article/2218763.html" target="_blank" title="在Javascript中处理数组之toSource()方法的使用"> <h2> 在Javascript中处理数组之toSource()方法的使用 </h2> </a> </li> <li> <a href="/article/2218780.html" target="_blank" title="JavaScript中用sort()方法对数组元素进行排序的操作"> <h2> JavaScript中用sort()方法对数组元素进行排序的操作 </h2> </a> </li> </ul> </div> </article> </div> </main> <footer><div class="box"><div class="ft_nav"><div class="ft_about"><p>关于网站</p><ul><li><a href="/sitemap.xml" target="_blank" title="网站地图">网站地图</a></li><li><a href="/list/2/" title="最新程序员文章站">最新程序员文章站</a></li></ul></div><div class="ft_contact"><ul><li>本站所有数据收集于网络如有侵犯到您的权益,请联系我们进行下架处理。</li><li class="email_show"></li></ul></div></div><div class="copyright"><div class="cr_left"><p> 备案号:<a href="https://beian.miit.gov.cn/#/Integrated/index" target="_blank">粤ICP备20058927号</a></p><p>© Copyright © 2020-2022 www.superweb999.com 程序员文章站. </p></div></div></div></footer> </body> </html>