Afrikaans
Akan
Albanian
Amharic
Arabic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
1 1
So, I did the math, 2
2
and since the beginning of the course, 3
3
we have studied, exactly 23 different array methods. 4
4
And that's really amazing. 5
5
And not just because, 6
6
23 is my favorite number, 7
7
but because that means, 8
8
that you cannot do everything you can imagine, with arrays. 9
9
Now, the problem is that, 10
10
choosing between 23 different methods, 11
11
is not always easy. 12
12
And especially when you just started learning about them. 13
13
Right? 14
14
So probably, in your mind right now, 15
15
there is a big confusion, 16
16
between all these methods, 17
17
and about which one to use, when. 18
18
So, to help you out with that, 19
19
I created this summary lecture, 20
20
with all the 23 array methods. 21
21
And I believe, that the best way to figure out, 22
22
which method to use, 23
23
in each situation, 24
24
is by starting to ask the question, 25
25
what do I actually want from this method? 26
26
So do I want to mutate the original array, 27
27
or do I want a new array? 28
28
Do I maybe want an array index, 29
29
or do I want to retrieve an entire array element? 30
30
Or do I want to know, 31
31
if an array includes, a certain element, 32
32
or maybe I just want to get a new string, 33
33
to transform the array to a new value, 34
34
or simply to loop over the array? 35
35
Well, these are a lot of different scenarios, 36
36
and by asking exactly these questions, 37
37
we can now categorize the methods, 38
38
and then easily choose between them. 39
39
So this is kind of a framework, that I developed, 40
40
and so let me go briefly, 41
41
through all of these different scenarios with you. 42
42
So these are the methods that mutate the original array. 43
43
So if we want to add an element, 44
44
to the original array, 45
45
we can use push or unshift. 46
46
So we already talked about all of these methods, 47
47
so of course I will not explain them again, 48
48
this is just a reference for you to keep. 49
49
Now anyway, if we want to remove, 50
50
from the original, 51
51
then we use either, 52
52
pop, shift or splice. 53
53
And finally, we also talked about, 54
54
three other methods that mutate the original array, 55
55
which is the reverse, sort and fill methods. 56
56
Okay. 57
57
So keep in mind, that you have to be careful, 58
58
because they do change the underlying array, 59
59
that we're working with. 60
60
And that many times is not what we want. 61
61
So if instead, we want a new array, 62
62
then we can use one of these methods. 63
63
So if we want to calculate one array, 64
64
from the original, then we use map methods. 65
65
And this one we use all the time, 66
66
as it loops over the original array, 67
67
and creates a new one, based on that. 68
68
We can also create new arrays, 69
69
by filtering for a condition, 70
70
or by taking a slice of the original array. 71
71
We can also concatenate two arrays, 72
72
and create a new array based on that, 73
73
and finally, we can flatten the original array, 74
74
using flat and flatMap. 75
75
Next, sometimes we need an array index. 76
76
And for that, 77
77
we have the indexOf and findIndex methods. 78
78
Now the difference between them, 79
79
is that findIndex can basically search, 80
80
for an element in the array, 81
81
based on a test condition, 82
82
that we provide, in the callback function. 83
83
But besides that, 84
84
they are pretty similar, 85
85
and both give us the index, 86
86
of a certain element in an array. 87
87
Now, if we actually need the array element itself, 88
88
then we use, the find method. 89
89
And so this one again, 90
90
is based on a test condition, 91
91
specified in a callback function. 92
92
Next up, sometimes it's very important to know, 93
93
whether an array includes, 94
94
a certain element or not. 95
95
And for that we have, 96
96
includes, some and every. 97
97
So with includes, 98
98
we can simply test, 99
99
if an array contains a single value, 100
100
while on the other hand, 101
101
with some and every, 102
102
we can specify a condition, 103
103
based on a callback function. 104
104
So some is gonna return, 105
105
if at least one of the elements in the array, 106
106
satisfies the condition, 107
107
and every, only returns true, 108
108
if all of the elements, 109
109
satisfy the condition. 110
110
So these three methods, 111
111
are all return Boolean values, 112
112
which is very helpful, 113
113
in a condition. 114
114
For example, in an if/else statement. 115
115
Okay. So that's where you many times will use, 116
116
one of these methods. 117
117
Next up, sometimes we want to transform an array, 118
118
into a string. 119
119
And then we use the join method. 120
120
Or we might want to reduce the entire array, 121
121
to just one value. 122
122
And as we already know, 123
123
for that, we use the reduce method, 124
124
just as we studied in this section. 125
125
So in the reduce method, we use an accumulator, 126
126
which has like a snowball, 127
127
to boil down, an entire array, 128
128
to just one single value. 129
129
And that value can be of any type. 130
130
So it can be a number, string, Boolean, 131
131
or even an array or an object. 132
132
All right? 133
133
And so in fact, we could, 134
134
replace some of these methods that we have here, 135
135
with a reduce. 136
136
Now, if all we want to do, 137
137
is to just loop over an array, 138
138
without producing any new value, 139
139
we use the, forEach method. 140
140
So remember, this one does not create a new array, 141
141
and in fact, it doesn't create any new value. 142
142
All we do in the forEach method is to, 143
143
basically just do some work, 144
144
but not produce a new value. 145
145
All right? And that's it. 146
146
That's an overview of all the 23 methods, 147
147
that we can use on arrays. 148
148
And it might be a good idea, 149
149
to somehow keep this overview handy. 150
150
For example, print it out on a paper, 151
151
or just store it somewhere, on your computer. 152
152
Anyway, now all there's left to do in the section, 153
153
is to complete the final coding challenge. 154
154
So let's do that right in the next video.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.