var Carlist = [{value: "Lu", Text: "L-lu"}, {value: "O", Text: "A-O"}, {value: "B", Text: "B"}, {value: "C", Text: "C"}, {value: "Chuan", Text: "C-Chuan"}, {value: "E", Text: "E-E"}, {value: "G", Text: "G"}, {value: "Gan", Text: "G-gan"}, {value: "GUI", Text: "G-gui"}, { Value: "Expensive", Text: "G-valued"}, {value: "Gan", Text: "G-gan"}, {value: "Port", Text: "G-Port"}, {value: "H", Text: "H"}, {value: "Black", Text: " H-Black "}, {value:" Shanghai ", Text:" H-Shanghai "}, {value:" J ", Text:" J "}, {value:" Jing ", Text:" J-Beijing "}, {value:" Tianjin ", Text:" J-Jin "}, {value:" Ji ", t Ext: "J-ji"}, {value: "Jin", Text: "J-Jin"}, {value: "Kat", Text: "J-Kat"}, {value: "K", Text: "K"}, {value: "L", Text: "L"}, {value: " Liao ", Text:" L-Liao "}, {value:" Mongolian ", Text:" M-Mask "}, {value:" Min ", Text:" M.-Min "}, {value:" n ", Text:" N "}, {value:" ning ", Text:" N-Ning "}, {VA Lue: "Green", Text: "Q-Green"}, {value: "Joan", Text: "Q-Joan"}, {value: "S", Text: "S"}, {value: "su", Text: "s-su"}, {value: "Shaanxi", Text: "S-Shaanxi" },{value: "Taiwan", Text: "T-table"}, {value: "V", Text: "V"}, {value: "WJ", Text: "WJ"}, {value: "Anhui", Text: "W-wan"}, {value: "Xiang", Text: "X-Xiang"}, {value: "New", text: "X-New"}, {value: "Yue", Text: "Y-Yue"}, {value: "Cloud", Text: "Y-Cloud"}, {value: "Yu", Text: "Y-yu"}, {value: "Yu", Text: "Y-yu"}, {value: "Z", Text: "Z"}, {value: "Zhe", Text: "Z-Zhe"}, {value: "Hidden", Text: "Z-Tibet"}]
var newcity = [];for (var i = 0;i< carlist.length;i++) {console.log (carlist[i].text); Newcity.push (Carlist[i].text);} Console.log (newcity);d ocument.write (newcity + "<br/>") document.write (Newcity.sort () + ' <br/> ');
var newcarlist = [];var cityname = [];for (var i=0;i<newcity.length;i++) {//Console.log (Newcity[i]); var value = Newcity [I].split ("-");//Console.log (Value[0]) var json = {value:value[0],text:newcity[i]}if (newcity[i] = = ' L-lu ') { Newcarlist.unshift (JSON);} Else{newcarlist.push (JSON);} if (value[1] = = null) {Cityname.push (value[0])}else {cityname.push (value[1]);}} Console.log (newcarlist) Console.log (json.stringify (newcarlist)) document.write (Json.stringify (newcarlist));
Add:
function Sortnumber (A, b) {return A-b}var arr = new Array (6) arr[0] = "ten" arr[1] = "5" arr[2] = "" arr[3] = "arr[4" = "100 0 "arr[5] =" 1 "document.write (arr +" <br/> ") document.write (Arr.sort (Sortnumber))
function Sortnumber (A, b) {return B-a}var arr = new Array (6) arr[0] = "ten" arr[1] = "5" arr[2] = "" arr[3] = "arr[4" = "100 0 "arr[5] =" 1 "document.write (arr +" <br/> ") document.write (Arr.sort (Sortnumber))
The sort () method is used to sort elements of an array. Arrayobject.sort (sortby) SortBy Optional. Specifies the sort order. Must be a function. Returns a reference to an array of values. Note that the array is sorted on the original array, and no replicas are generated. Description if the method is called without parameters, the elements in the array are sorted alphabetically, more precisely, by the order in which the characters are encoded. To do this, you should first convert the elements of the array to a string, if necessary, for comparison. If you want to sort by other criteria, you need to provide a comparison function that compares two values and returns a number that describes the relative order of the two values. The comparison function should have two parameters A and B, whose return value is as follows: If A is less than B, a value less than 0 is returned if a should appear before B in the sorted array. If a equals B, 0 is returned. If a is greater than B, a value greater than 0 is returned.
Sorting of array data sort