Requirements are: Count the number of times and order according to requirements;
Ideas:
The first step: stitching strings, returning an array of strings;
The second step: Query the array, go to the weight and count the number;
Step three: Sort by using the sort () function;
Fourth step: Join () function. Put the elements of the array into the string, it is really around, learn the program is not the way, more practice.
<!doctype Html>"Utf-8"><title> array de-reordering statistics sort </title><style>Body {text-Align:center;}</style><script>window.onload=function () {varObtn=document.getelementbyid ('BTN1'); varOtext1=document.getelementbyid ('txt1'); varOtext2=document.getelementbyid ('txt2'); Obtn.onclick=function () {varjson={}; varArr=otext1.value.split (' '); for(varI=0; i<arr.length; i++) { varValue=Arr[i]; if(Json[value]) {Json[value]++; } Else{Json[value]=1; } } //alert (json.stringify (JSON)); /*[{name:i, Num:json[i]}, {name:i, Num:json[i]}, {name:i, num: Json[i]}]*/ varArr2=[]; for(varIinchJSON) {Arr2.push ({name:i, num:json[i]}); } //Console.log (ARR2);Arr2.sort (function (j1,j2) {returnj2.num-J1.num; }); vararr3=[]; for(varI=0; i<arr2.length;i++) { varjson=Arr2[i]; Arr3.push (json['name']+':'+json['Num']); } otext2.value=arr3.join ('\ n'); };}; function Findinarr (arr, obj) { for(varI=0; i<arr.length; i++) { if(arr[i]==obj) { return true; } } return false;}</script>Enter the original text (space separated):<br><textarea style="width:300px; height:200px;"Id="txt1"> Clothes sneakers Basketball shoes running shoes casual shoes canvas shoes football shoes clothes clothes clothes running shoes running shoes running shoes running shoes casual shoes canvas shoes casual shoes canvas shoes casual shoes Canvas shoes </textarea><br><br><in Put type="Button"Value="Change"Id="BTN1"/><br><br>here output:<br><textarea style="width:300px; height:200px;"Id="txt2"></textarea></body>Array de-reordering statistics sort