-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArrays.html
107 lines (84 loc) · 2.13 KB
/
Arrays.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
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
<!-- in this lesson: -->
<!-- ------------------- -->
<!--
Lesson 11 : Arrays & Loops
1. Arrays = List of values
2. Loops (while loop, for loop)
3. Accumulator pattern
4. Created a todo list project
5. Array are references, destructuring
6. More feature in loops: break, continue, loops inside a function
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
</head>
<body>
<script>
//🟨 Basics of Arrays :
var myArray = [1, 2, 3]
console.log(myArray)
console.log(myArray[1])
myArray[0] = 4
console.log(myArray)
//🟨 Syntax Rules for Arrays [] :
//🟩 [ List , of , values ]
//🟩 const myArray = [ 1, 2, 3 ]
// INDEX --> 0 1 2
//🟦 Inside of Array we can put any type of value
var myArray = [1, "hello", true, { name: "bob" }, [1, 2]]
console.log(typeof [1, 2])
console.log(Array.isArray([1, 2])) //true
console.log(Array.isArray(true))
console.log(Array.isArray("hello"))
//🟨 .push() - Adds a value to the end of the array
myArray.push(100)
console.log(myArray)
//🟨 .splice() - Removes a value from an array
myArray.splice([5]) //100
console.log(myArray)
//🟨-----------------PART-2-----------------
const array1 = [1, 2, 3]
const array2 = array1.slice()
array2.push(1)
console.log(array1)
console.log(array2)
const [firstValue, secondValue] = [1, 2, 3]
for (let i = 1; i <= 10; i++) {
if (i % 3 === 0) {
continue //🟨Skip
}
console.log(i)
if (i === 8) {
break //🟨Stop
}
}
let a = 1
while (a <= 10) {
if (a % 3 === 0) {
a++
continue
}
console.log(a)
a++
}
function doubleArray(nums) {
let numsDoubled = []
for (let i = 0; i < nums.length; i++) {
const num = nums[i]
if (num === 0) {
return numsDoubled
}
numsDoubled.push(num * 2)
}
// console.log(numsDoubled)
return numsDoubled
}
// doubleArray([1, 1, 3])
console.log(doubleArray([1, 0, 3]))
</script>
</body>
</html>