forked from KelvinMuriithi/html-css-js-recap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrays.js
More file actions
26 lines (24 loc) · 728 Bytes
/
arrays.js
File metadata and controls
26 lines (24 loc) · 728 Bytes
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
let numbers = [1, 2, 3, 4, 5];
console.log(numbers)
// console.log(numbers[0])
// console.log(numbers[1])
// console.log(numbers[2])
// console.log(numbers[3])
// console.log(numbers[4])
// console.log(numbers[5]) // undefined
// array operations
// adding an element to the end of the array
// numbers[5] = 6
// numbers.push(6)
// console.log(numbers)
// adding an element to the beginning of the array
// numbers[0] = 0
// numbers.unshift(0)
// console.log(numbers)
// removing the last element of the array
// numbers.pop()
numbers.splice(numbers.length - 1, 1)
console.log(numbers)
// console.log(numbers.length) // 1
let mixedArray = [1, "Hello", true, null, undefined, {name: "Alice"}, [1, 2, 3]]
console.log(mixedArray)