Jump to content

sorting.............


pankaj.ghadge

Recommended Posts

suppose i have a class function user(){ this.id=""; this.name=""; this.status=0;}and i have taken array var user_array=new Array();user_array[user_array.length]=new user();user_array[user_array.length-1].id="a01";user_array[user_array.length-1].name="xxxx";user_array[user_array.length-1].status=4;user_array[user_array.length]=new user();user_array[user_array.length-1].id="a02";user_array[user_array.length-1].name="yyyy";user_array[user_array.length-1].status=3;user_array[user_array.length]=new user();user_array[user_array.length-1].id="a04";user_array[user_array.length-1].name="AAAA";user_array[user_array.length-1].status=1;And i want to sort the array by status and display the value like as follows.0a4 AAAA 10a2 YYYY 30a1 XXXX 4so how to do this...............................please tell me....................................

Link to comment
Share on other sites

something like this should work

function sort(sorter,arr) {	var temp;	for(var i=0;i<arr.length;i++) {		for(var j=0;j<arr.length-1;j++) {			if((arr[j])[sorter] > (arr[j+1])[sorter]) {				temp = arr[j+1];				arr[j+1] = arr[j];				arr[j] = temp;			}		}	}}sort('status',user_array);

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...