After referring to the Wuyou cosin method (thank you), the finishing method is as follows
//A random number, used for simulation
var baseNum=[];
for(var i= 0;i< 100000 ;i ){
random = Math.floor(Math.random( )*i);
baseNum.push(random);
}
var baseNumLen = baseNum.length;
var numSubscript = [];
//Use numbers as subscripts and values Put it into another array to achieve sorting and non-repetition
for (var i =0;iif(numSubscript[baseNum[i]] == undefined)numSubscript[baseNum[i ]]=baseNum[i];
}
//Remove empty values and reverse them
baseNum = numSubscript.join(',').replace(/([,] )/ig, ' ,').split(',').reverse();
document.write(baseNum);
Off topic:
If the array is generated by yourself, customer service will write This code is just fine. (Awesome)
var baseNum=[],tmp= {},v;
for(var i= 0;i< 100000 ;i ){
tmp[Math.floor(Math.random()*i)]=true;
};
i=0;
for (var k in tmp){
baseNum[i ]=k;
};
baseNum.sort(fn);
function fn(x,y ) {
return x-y>0?1:-1
}
document.write(baseNum.join(''));