FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JavaScript-Learning/array-sort.html at master · xiazhe/JavaScript-Learning · GitHub
xiazhe
/
JavaScript-Learning
Public
Notifications
You must be signed in to change notification settings
Fork
3
Star
4
Code
Issues
0
Pull requests
1
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
JavaScript-Learning
/
array-sort.html
Copy path
More file actions
More file actions
Latest commit
History
History
History
34 lines (31 loc) · 719 Bytes
Breadcrumbs
JavaScript-Learning
/
array-sort.html
Copy path
File metadata and controls
34 lines (31 loc) · 719 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<!DOCTYPE html
>
<
html
lang
="
en
"
>
<
head
>
<
meta
charset
="
UTF-8
"
>
<
title
>
Array.prototype.sort()
</
title
>
</
head
>
<
body
>
<
script
>
//https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array/sort
var
items
=
[
{
name
:
'Edward'
,
value
:
21
}
,
{
name
:
'Sharpe'
,
value
:
37
}
,
{
name
:
'And'
,
value
:
45
}
,
{
name
:
'The'
,
value
:
-
12
}
,
{
name
:
'Magnetic'
}
,
{
name
:
'Zeros'
,
value
:
37
}
]
;
items
.
sort
(
function
(
a
,
b
)
{
if
(
a
.
value
>
b
.
value
)
{
return
1
;
}
if
(
a
.
value
<
b
.
value
)
{
return
-
1
;
}
// a 必须等于 b
return
0
;
}
)
;
console
.
log
(
items
)
;
</
script
>
</
body
>
</
html
>
Back
|
FazBrowse Home
|
New Git URL