-
Notifications
You must be signed in to change notification settings - Fork 0
/
Array.js
59 lines (35 loc) · 1.54 KB
/
Array.js
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
// 1) What is the array?
// A collection of indexable, ordered, comma separated items, of any data type.
// The indexes are automatically created for you.
// In other words, a list of values.
// The first value is at index 0.
// Useful when you have a colleciton of related items.
// 2) How to create an array?
// const myArray = [1, 2, 3]
//const myArray = new Array(3).fill(true)
// const myArray = Array.from('hello') // Common when working with DOM elements
// console.log({myArray})
// 3) Howe to access the values in an arra?
const exampleArray = ['first', 2, 3, 4, 'last']
const first = exampleArray[0]
const last = exampleArray[exampleArray.length - 1]
const three = exampleArray[2]
console.log({first, last, three})
// 4) What are some algorithmic complexity considerations for arrays?
// Inser/delete from the end of an array is very fast. Inser and delete any where else is lenear
// Getting an index is very fast
// Setting an index is very fast
// Creating an array is linear
// Searching an unsorted array is linear
// 5) Array are objects
console.log(typeof [1,2,3])
console.log(Array.isArray([])) // {} false
// You can add values to an array similar to objects
const myArray = []
myArray.bestDeveloper = 'Ruslan Tsykaliak'
console.log(myArray.bestDeveloper)
// JavaScript won't add . properties to the length of an array
console.log(myArray.length)
myArray[0] = 'first value'
console.log(myArray.lenght)
// So, what makes an object different than an array? Most the built in methods. (.length, .push, .pop, .filte, .map, etc.)