var arr = [2, 34, 4, 0, 234, 5]; function sortNumber(a, b) { return a - b; } alert(arr.sort(sortNumber).join()); console.log(arr.sort(sortNumber));