-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray.html
57 lines (44 loc) · 1000 Bytes
/
array.html
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
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>JS Array</h1>
<p>unshift()</p>
<button id="button" onclick="arr()">try it</button>
<p id="demo"></p>
<script>
var fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("demo").innerHTML = fruits;
function arr(){
console.log(contains(fruits, "Lemon"));
if (contains(fruits, "Lemon") == false){
fruits.unshift("Lemon");
}
console.log(contains(fruits, "Lemon"));
document.getElementById("demo").innerHTML = fruits;
}
function contains(arr, element){
for (i in arr){
if (arr[i] == element){
return true;
}
}
return false;
}
//arr = ["a", "b", "c", "d", "e"];
//for (i in arr){
// console.log(arr[i]);
//}
//验证while(0)是否会执行: 不会
//学到: len--是先执行再减一
//var len = 5;
//while(len--){
// console.log(len);
//}
//while(0){
// console.log("heelow");
//}
</script>
</body>
</html>