This article mainly introduces the random x data from the array of the JS code, the need for friends can refer to the
Some operations on the array are frequently encountered in the work 1. Random x data from the data (PS: The following s.each is the Kissy.each method, you can change to a for loop) code as follows:/* random x from the array arr of data not duplicated */ function Myrand (arr,num) { var newArr = []; rand (num); //random x FUNCTI On rand (k) { if (k==0) { return; & nbsp } var index = Math.floor (Math.random () * arr.length); var flag = true; S.each (newarr,function (v) { if (v = = Arr[index]) {&nbs P flag = false; } } if (flag) { Newarr.push (Arr[index]) &NB Sp k--; } Rand (k); } return NEWARR; &NBSP} 2. Random x data from object code as follows:/* Randomly take x */function Myrand () {   from Object obj ; var S = Kissy; var obj={ : {name: ' A '}, ': {name: ' B '}, & nbsp ': {name: ' C '}, ': {name: ' d '}, ': {name: ' E '}, & nbsp ' a ': {name: ' F '}, ' ': {name: ' G '}, ': {name: ' H '}, ': {name: ' I '}, ': {name: ' G '} }; var arr = []; S.each (obj,function (v,k) { Arr.push (k); }); //randomly take 3 var newArr = Myrand (arr,3); S.each (newarr,function (b) { Console.log (obj[b]); })}; 3. Remove duplicates of array code as follows:/* Remove duplicate of array */function Uniqarr (arr) { function toobject (a) { &nbs P var o = {}; for (Var i=0, j=a.length i<j; i=i+1) { O[a[i]] = True } return o; }; function keys (o) { var a=[], I; (i in O) {  ; if (O.hasownproperty (i)) {//Here, Yui Source is Lang.hasownproperty (o, i) A.push (i); { } return A; }; Return keys (Toobject (arr)); }