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
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
Persian
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
In JavaScript,
there are three big and important array methods
that we use all the time to perform data transformations.
So basically,
these are methods that we use
to create new arrays based
on transforming data from other arrays.
And in recent years,
these tools have become really popular and for good reasons
and therefore you'll see them everywhere you look
in Modern JavaScript.
And the tools I'm talking about are; map, filter and reduce.
So these are three array methods
and in this lecture,
I'm gonna give you a quick overview of them.
Then over the next couple of lectures,
we're gonna dive deep into these three methods
in practice so that we can use them
throughout the rest of the course.
First the map method is yet another method that we can use
to loop over arrays.
So, map is actually similar
to the forEach method that we studied before
but with the difference that map creates a brand new array
based on the original array.
So essentially the map method takes an array,
loops over that array
and in each alteration,
it applies a covic function
that we specify on our code
to the current array element.
So in this example we say that each element
shall be multiplied by two.
And with this covic in place,
the map method multiplies every single element by two
and puts it into a new array.
We say that it maps the values of the original array
to a new array and that's why this method is called map.
And it is extremely useful.
Usually way more useful than in forEach method
because forEach simply allows us to do some work
with each array element.
But map on the other hand,
builds us a brand new array
containing the results of applying an operation
to the original array,
all right?
And we will use the map method
in practice right in the next video.
Anyway,
next up we have the filter method,
which as the name says, is used to filter for elements
in the original array which satisfy a certain condition.
So in this example we are only looking
for elements greater than two.
So all the elements that pass the test
that we specified will make it into a new filtered array.
Or in other words elements for which the condition is true
will be included in a new array
that the filter method returns.
All other elements will get filtered out
so they will not be included in the new array.
And finally there is also the reduce method
which we use to boil down all the elements
of the original array into one single value.
And an example of this can be to add all the elements
of an array together.
But we can also do many other interesting things.
So for the example of adding up all numbers in the array,
we need to specify an operation like this one
where we have an accumulator variable.
Then as the reduce method loops over the array,
it keeps adding the current element onto the accumulator
until at the end of the loop we have
to total sum of all the elements.
So you can imagine this as a snowball,
it keeps getting bigger and bigger
as it rolls down a hill.
And so this is known as the snowball effect
and reduce is pretty similar to that,
okay?
So keep that in mind as a nice analogy.
Now we also said that this whole process
has now reduced the original array to one single value
which in this case is the sum of all the elements
but it can of course be many other operations.
Now it's this value that then actually gets returned
from the reduce method in the end.
So there is no new array in this case
but only the reduced value.
Now this probably sounds more complicated
than it actually is.
And so let's start to put it
into practice 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.