运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
转到 Spaces
<!DOCTYPE html> <html> <body> <h1>JavaScript Arrays</h1> <h2>The sort() Method</h2> <p>Click the button (again and again) to sort the array in random order.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> const points = [40, 100, 1, 5, 25, 10]; document.getElementById("demo").innerHTML = points; function myFunction() { points.sort(function(){return 0.5 - Math.random()}); document.getElementById("demo").innerHTML = points; } </script> </body> </html>