var arr = [9,1,2,5,4,6,5,8]; function sort_arr (arr){ var temp ,_arr = arr,count = _arr.length; for(var i=0;i< count;i++){ for(var j=i+1; j<count;j++){ if(_arr[i]>_arr[j]){ temp=_arr[i]; _arr[i] = _arr[j]; _arr[j] =temp; } } } return arr; } alert(sort_arr(arr));