Skip to content

Commit 74f40b6

Browse files
authored
Create 数组原型对象的创建.html
1 parent 1e4900f commit 74f40b6

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

数组原型对象的创建.html

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<title>Document</title>
6+
</head>
7+
<body>
8+
9+
</body>
10+
<script>
11+
var arr = [23,25,45,12,59,2,15,4,4,4,4];
12+
console.log(arr);
13+
14+
Array.prototype.sortNum = function ()/*排序 冒泡*/
15+
{
16+
var nun;
17+
for(var i=0; i<this.length; i++)
18+
{
19+
for(var j=i+1; j<this.length; j++)
20+
{
21+
22+
if(this[i]>this[j])
23+
{
24+
num = this[j];
25+
this[j] = this[i];
26+
this[i] = num;
27+
}
28+
}
29+
30+
}
31+
return this;
32+
}
33+
34+
Array.prototype.delSame = function ()/*去重*/
35+
{
36+
var arr1 = [];
37+
var json1 = {};
38+
var arr4 = this;
39+
for(var i=0; i<arr4.length; i++)
40+
{
41+
if(!json1[arr4[i]])
42+
{
43+
arr1.push(arr4[i]);
44+
json1[arr4[i]] = 1;
45+
}
46+
}
47+
return arr1;
48+
}
49+
console.log(arr.sortNum());
50+
console.log(arr.delSame());
51+
52+
console.log(arr);
53+
54+
55+
56+
var str = "hello word";
57+
String.prototype.revers = function (){
58+
var arr1 = this.split("");
59+
var arr2 = [];
60+
var j=0;
61+
62+
for(var i=0; i<arr1.length; i++)
63+
{
64+
arr2.push(arr1[arr1.length-j-1]);
65+
j++;
66+
}
67+
var arr3 = arr2.join("");
68+
return arr3;
69+
}
70+
console.log(str.revers());
71+
72+
73+
</script>
74+
</html>

0 commit comments

Comments
 (0)