DEV Community

Discussion on: `at` coming soon to ECMAScript

Collapse
 
laurieontech profile image
Laurie

Yes, you could loop through in reverse. The first non-element would return undefined.

Collapse
 
laurieontech profile image
Laurie

Yes, if you have holes then you'll need to check relative to the length of your array.

 
edo78 profile image
Federico "Edo" Granata

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 item

Collapse
 
edo78 profile image
Federico "Edo" Granata

Sadly 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.