Home > Web Front-end > JS Tutorial > body text

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

WBOY
Release: 2016-05-16 17:49:59
Original
1591 people have browsed it

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
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template