Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

261
Views
Using Array.at(index) instead of Array[index] in JavaScript

I have a question about Array.at() method that was introduced Array.prototype.at() - MDN. It seems more useful than squared brackets annotation arr[i] since there is an option to specify index starting from the end of an array, for example: arr.at(-1) which would return the last member of arr array. Also, it seems more appropriate for method chaining. Are there any downsides to switching to it?

over 4 years ago · Santiago Trujillo
4 answers
Answer question

0

A couple of disadvantages to it are:

  • It's a very new method. Older browsers will not be able to understand your code if you use it, unless you include a polyfill - so make sure you include one..
  • On a completely different track, since it's such a new method, I wouldn't be surprised if a substantial number of developers haven't heard about it - using .at may confuse some of them (and cause them to have to look it up). Not that this means that you shouldn't use it, but it's something to keep in mind.
over 4 years ago · Santiago Trujillo Report

0

Another disadvantage that code can redefine this function. This may be a security concern

Array.prototype.at = () => console.log("🔥"); 
over 4 years ago · Santiago Trujillo Report

0

The Array.at() method is under experiment at present and it might get change as developers around the world will test and create loopholes, ofcourse.

Though, you can use the polyfill and things get easy for you as any future change on the experiment will not affect your code and it will not break apart.

Also, the method might work with both () and [] which is a quite confusing thing. It is mentioned in the mozilla official docs as: This is not to suggest there is anything wrong with using the square bracket notation.

So, it is not recommendable to use array.at now.

enter image description here

over 4 years ago · Santiago Trujillo Report

0

Only improvements I think. Similar to python code JS can now view a array with index -1 to indicate the last element.

a = [1,2,3]
a[a.length-1] # 3

or

a.at(-1) #3
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!