-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy patharray.html
63 lines (45 loc) · 1.29 KB
/
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
58
59
60
61
62
63
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="ja" xml:lang="ja" dir="ltr" xmlns:og="http://ogp.me/ns#" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title> Array </title>
</head>
<body>
<div>
Array
</div>
<script>
// create array
// way 1
const arr1 = [1, 2, 3, 4, 5]
// way 2
const arr2 = Array.from(new Array(5), (_, i) => i + 1)
// way 3
const arr3 = []
for(let i = 0; i < 10; i++) {
arr3.push(i)
}
// access item array
const firstEle = arr1[0];
const lastEle = arr1[arr1.length - 1]
// loop array
const fruits = ['Apple', 'Banana', 'Orange']
fruits.forEach(function(item, index, array) {
console.log(item, index)
})
const tableTotalData = [1,2,3];
const totalData = [...tableTotalData];
totalData[0] = 5
console.log('totalData: ', totalData)
console.log('tableTotalData: ', tableTotalData)
const tableObject = {
id: 1,
title: 'abc'
};
const totalObject = {...tableObject};
totalObject.id = 3
totalObject.title = 'truong'
console.log('totalObject: ', totalObject)
console.log('tableObject: ', tableObject)
</script>
</body>
</html>