Source
<!DOCTYPE HTML><HTML> <Head> <MetaCharSet= "Utf-8" /> <title></title> </Head> <Body> <Script> varary=["Ding Shao"," Wang Xin","Ding Shao"]; Ary.sort (); //sort the array alphabetically varRes= []; for(varI= 0; I<ary.length;) {varCount= 0; for(varJ=i;j<ary.length;j++){if(Ary[i]==Ary[j]) {Count++;}} Res.push ([Ary[i],count]); I+=count; } //Res holds the number of repetitions of values and values in a two-dimensional dimension for(varI= 0; I<Res.length;i++) {Document.writeln (Res[i]+"<br/>");} </Script> <!--is the first sort, then find the same content, if the same, there will be accumulated values, and then I self-add, skip the same number, and start again to judge the other example has an array of arr 11122 is I starting from 0, and then Coun T is 3, and the second one is 3, starting with the fourth number . - </Body></HTML>
To find the number of occurrences of an array element