All language subtitles for 143 The new at Method.en_US1

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
is Icelandic
ig Igbo
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranรฎ)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

There's a new,

very simple array method in ES2022,

which is the At Method.

And so let's take a look at it.

And let's start by creating some dummy array.

So, 23, 11, 64.

So just three random values here.

And then, if we wanted to take one of the values

out of the array,

let's say the first one,

then we would traditionally do this, right?

So array at position zero.

So that's basically what this means.

But now with the new At Method,

we can do the exact same thing using a method.

And, as you can guess, that is the At Method.

Then we specify the exact same index here,

and then we get the exact same value.

So basically now we do what we say here.

So here we say, array at position zero.

And so that's why this new method is called

array dot at position zero.

So very, very simple, right?

So basically we can now replace

the traditional bracket notation

with the more modern looking At Method,

if we prefer to use array methods like this.

Now, maybe this doesn't look all too useful.

So, what's the big deal here?

Well, actually there is one particularity of the At Method,

which makes it quite useful to use

instead of the brackets notation.

So, let's now say that we wanted to get

the last element of the array.

Now, supposing that we do not know the length of the array,

we would write something like this.

So, array at the position of

array dot length minus one.

And that will then give us 64.

So, array dot length is the length of the array,

which a three,

but the last position here is position number two

because the array is zero-based.

So the indexes are zero-based.

So zero, one, two.

And so therefore,

whenever we want to get the last element of an array,

we always subtract one from the length.

So this is quite a common scenario in JavaScript.

And that's why there's also another solution.

So another way is to use the slice method

that we just learned before.

So arr dot slice.

And with this,

we can then get a copy of the original array.

And here we can use minus one to get

the last element of the array, right?

So just like we learned in the previous lecture.

So, here we get that copy of the array

only with the last element.

So of course we want the value,

and so then we need to take out that first value

by doing square brackets zero.

Now, right.

So these are the two more traditional ways of solving

the problem of getting the last element.

However, as you can probably guess,

the new At Method makes this process even easier.

So now all we have to do is to write arr dot at,

and now here we can write the exact same negative in nexus,

then we can write in the slice method.

And so if we lock this now,

then here again we have 64.

So the negative index, just like in slice,

basically starts counting from the right side here.

So from the end of the array.

And so we could also write, minus two.

So, minus one and minus two.

So this should give us 11.

And indeed here is that 11.

But most of the time,

the thing that we're most interested in here

is this minus one, to get the last element of the array.

And that's actually it.

Now the only question is,

should you use this new At Method

or should you keep using the bracket notation?

Well, as always, it depends.

So, if you want to get to the last element of an array,

or basically start counting from the end of an array,

then you should probably start using the At Method.

Also, if you want to do something called "method chaining",

which we will talk about later in this section,

then the At Method is also perfect for that.

So basically combining multiple methods

all at the same time.

And then, it's quite helpful to use

the At Method instead of the brackets notation.

Now, on the other hand,

if you just want to quickly get a value from an array,

so just like the first element,

then of course you can keep using the brackets notation.

And personally, I also do that all the time.

So basically if all you want to do is something like this,

then you can simply keep using the square brackets.

Okay.

Oh, and by the way,

I actually also wanted to let you know that the At Method

also works on strings.

So, let's look to the console.

A string,

let's say jonas and then here we can also use

the At Method.

For example, let's say, at zero.

And so that will give us J,

and then of course we can also

get the last character off the string

by using at minus one.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.