forked from Pankaj-Str/JavaScript-Tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample.html
More file actions
113 lines (88 loc) · 2.97 KB
/
Example.html
File metadata and controls
113 lines (88 loc) · 2.97 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<!-- <script src="JavaScriptArray.js"></script> -->
<script>
// Array Empty
data = []
// print array
console.log(data)
// data array
data = [1,2,3,4,5]
console.log(data)
// find length
console.log(data.length)
// using push()
data.push(6,7,8)
console.log(data)
// using pop()
data.pop()
console.log(data)
// using unshift()
data.unshift(0)
console.log(data)
// shift()
data.shift()
console.log(data)
// concat()
data2 = [9,10,11]
console.log(data.concat(data2))
// splice()
fruits = ["apple", "banana", "cherry"];
removedFruit = fruits.splice(2, 1, "orange", "kiwi","Mango");
console.log(fruits)
// slice()
fruits = ["apple", "banana", "cherry", "date", "elderberry"];
slicedFruits = fruits.slice(1, 3);
console.log(slicedFruits)
// join()`
fruits = ["apple", "banana", "cherry"];
console.log(fruits.join(" | "))
fruits = ["apple", "banana", "cherry", "date", "elderberry"];
slicedFruits = fruits.slice(2, 4);
console.log(slicedFruits)
// indexOf()
fruits = ["apple", "banana", "cherry", "date", "elderberry"];
console.log(fruits.indexOf("cherry"))
// lastIndexOf()
fruits = ["apple", "banana", "cherry", "date", "elderberry",
"cherry", "fig", "grape","cherry"];
console.log(fruits.lastIndexOf("cherry"))
// forEach()
fruits = ["apple", "banana", "cherry"];
fruits.forEach(function(item, index, array) {
console.log(item + " is at index " + index);
});
// map()
fruits = ["apple", "banana", "cherry"];
newFruits = fruits.map(function(item) {
return item.toUpperCase();
});
console.log(newFruits)
// filter()
fruits = ["apple", "banana", "cherry", "date", "elderberry"];
newFruits = fruits.filter(function(item) {
return item.length > 7;
});
console.log(newFruits)
// every()
numbers = [2, 4, 6, 8, 10];
isEven = numbers.every(function(number) {
return number % 2 === 2;
});
console.log(isEven)
// fill()
fruits = ["apple", "banana", "cherry", "date", "elderberry"];
fruits.fill("grape", 2, 4);
console.log(fruits)
// flat()
numbers = [1, 2, [3, 4, [5,6]], 7, 8, [9, 10]];
console.log(numbers.flat(2))
</script>
</head>
<body>
</body>
</html>