-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathjavascript-array-methods.html
More file actions
60 lines (60 loc) Β· 1.87 KB
/
Copy pathjavascript-array-methods.html
File metadata and controls
60 lines (60 loc) Β· 1.87 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>javascript : Array.unshift && Array.push && Array.pop && Array.shift</title>
</head>
<body>
<div>
<div>
<pre>
<code>var fruits = ["Banana", "Orange", "Apple", "Mango"];</code>
<code>fruits.unshift("Kiwi","Lemon","Pineapple")</code>
<code>fruits.push("Kiwi","Lemon","Pineapple")</code>
<code>fruits.shift("Kiwi","Lemon","Pineapple")</code>
<code>fruits.pop("Kiwi","Lemon","Pineapple")</code>
<kbd>Ctrl</kbd>+<kbd>Shift</kbd>
</pre>
<!-- -->
<p id="demo1">unshift() ζΉζ³ε―εζ°η»ηεΌε€΄ζ·»ε δΈδΈͺζζ΄ε€ε
η΄ οΌεΉΆθΏεζ°ηιΏεΊ¦γ</p>
<button onclick="myUnshift()">Try it</button>
<!-- -->
<p id="demo2">push() ζΉζ³ε―εζ°η»ηζ«ε°Ύζ·»ε δΈδΈͺζε€δΈͺε
η΄ οΌεΉΆθΏεζ°ηιΏεΊ¦γ</p>
<button onclick="myPush()">Try it</button>
<!-- -->
<p id="demo3">shift() ζΉζ³η¨δΊζζ°η»η第δΈδΈͺε
η΄ δ»ε
ΆδΈε ι€οΌεΉΆθΏε第δΈδΈͺε
η΄ ηεΌγ</p>
<button onclick="myShift()">Try it</button>
<!-- -->
<p id="demo4">pop() ζΉζ³η¨δΊε ι€ζ°η»ηζεδΈδΈͺε
η΄ εΉΆθΏεε ι€ηε
η΄ γ</p>
<button onclick="myPop()">Try it</button>
</div>
<script>
var fruits = ["Banana", "Orange", "Apple", "Mango"];
//
function myUnshift(){
fruits.unshift("Kiwi","Lemon","Pineapple")
var x=document.getElementById("demo1");
x.innerHTML=fruits;
}
//
function myPush(){
fruits.push("Kiwi","Lemon","Pineapple")
var x=document.getElementById("demo2");
x.innerHTML=fruits;
}
//
function myShift(){
fruits.shift("Kiwi","Lemon","Pineapple")
var x=document.getElementById("demo3");
x.innerHTML=fruits;
}
//
function myPop(){
fruits.pop("Kiwi","Lemon","Pineapple")
var x=document.getElementById("demo4");
x.innerHTML=fruits;
}
</script>
</div>
</body>
</html>