Suppose that the array a = [1pr 2pr 3je 4], put it in another array b, in which the elements in the array an are randomly generated, how do you write it?

suppose that the array a = [1 # 2jue 3 # 4], put it in another array b, in which the elements in the array an are randomly generated, how do you write it?

var a = [1,2,3,4];

b = [2,3,1,4]//
Apr.03,2021

it is not quite clear whether you want to disorder the array elements (elements can not be repeated), or simply regard the original array as a generator to generate new elements to fill the new array (that is, elements can be repeatable).

if it is the former, shuffle algorithm _ Baidu search ;


the easiest way.
Array A disrupts sorting.
[1, return Math.random, 2, 3, 4, 5, 6] .sort (function (a, b) {return Math.random () > 0.5})

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3b28b-412b1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3b28b-412b1.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?