Home  >  Article  >  Web Front-end  >  js implementation code for sorting numbers in an array from small to large_javascript skills

js implementation code for sorting numbers in an array from small to large_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:49:591537browse

Example 1
In this example we will create an array and sort it alphabetically:


[Ctrl A Select all Note: If you need to introduce external Js, you need to refresh to execute
]

Output:

Jani,Hege,Stale,Kai Jim,Borge,Tove
Borge,Hege,Jani,Kai Jim,Stale,Tove Example 2
In this example we will create an array and sort it alphabetically:

[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
]

Output:

10,5,40,25,1000,1
1,10,1000,25,40,5 Please note that the above code does not sort the numbers according to the size of the value. To achieve this, you must Use a sorting function:
[Ctrl A Select all Note:
If you need to introduce external Js, you need to refresh to execute
]

Output: 10,5,40,25,1000,1 1,5,10,25,40,1000
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn