The random shuffle of JavaScript array to realize random shuffling function

Source: Internet
Author: User
Tags random shuffle shuffle javascript array

This article mainly introduced the JavaScript array random arrangement realizes the random shuffle function the method, relates to the JavaScript to realize the array random arrangement technique based on the List.sort method, may apply in the random shuffle, very has the practical value, the need friend may refer to under

In this paper, we describe the method of random shuffling of JavaScript array to realize random shuffle function. Share to everyone for your reference. The specific analysis is as follows:

This JS code can be in the array of elements of random arrangement, this is very useful, such as we play poker when you can arrange cards, that is, computer shuffle.

1 2 3 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 help you with your JavaScript programming.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.