As described here it looks like .at() is barely useful to get the last item.
It's unclear if it can be used to loop through the array in reverse (eg. .at(-2)) because we could have an hard time figuring when we reach the first element and stop the loop.
Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
Because they're not wrong. Let is just as valid as const from the perspective of the code. Without larger context it's just a preference. And you understood the example they were kind enough to provide just fine. Your response was to make yourself feel smart.
Maybe I'm missing somethig as english isn't my first language but using const is wrong.
Javascript prevent you from reassigning a value to a const throwing an error TypeError: Assignment to constant variable.
I was the first one asking a question because I know that I don't know everything and I want to learn so I think others can appreciate if I reciprocate
Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
Software dev at Netflix | DC techie | Conference speaker | egghead Instructor | TC39 Educators Committee | Girls Who Code Facilitator | Board game geek | @laurieontech on twitter
As described here it looks like
.at()
is barely useful to get the last item.It's unclear if it can be used to loop through the array in reverse (eg.
.at(-2)
) because we could have an hard time figuring when we reach the first element and stop the loop.So we still have to use
.length
like in the classic wayWe just shifted the
1
from thelength - 1
to the starting pointI'm struggling to see why we need
.at()
BTW You should cange
const
tolet
in your exampleYou're right. I never use classic for loops anymore really. Too used to writing:
I agree though. Don't see the point of at. Equally if you wanted to iterate the loop in reverse:
They gave you an example. You really don’t need to “correct” it.
What's wrong with that? I saw that he already edited it because he used "0" as a starting point instead of "1", so I thought he would like a fix.
Because they're not wrong. Let is just as valid as const from the perspective of the code. Without larger context it's just a preference. And you understood the example they were kind enough to provide just fine. Your response was to make yourself feel smart.
Maybe I'm missing somethig as english isn't my first language but using
const
is wrong.Javascript prevent you from reassigning a value to a const throwing an error
TypeError: Assignment to constant variable.
I was the first one asking a question because I know that I don't know everything and I want to learn so I think others can appreciate if I reciprocate
Yes, you could loop through in reverse. The first non-element would return undefined.
Yes, if you have holes then you'll need to check relative to the length of your array.
sure or you should do as suggested here dev.to/hisuwh/comment/1fcp7
I still miss the value of
.at()
beside being a sugar syntax to get the last itemSadly you can't just check for an undefined element because array with "hole" like
const arr = [1,,3,4];
can create a problem with that logic.