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

404
Views
what is at() method in JavaScript?

Array.prototype.at()

what is .at() method in JavaScript?

const myList = ['index0', 'index1', 'index2']

myList.at(1) // 'index1'
mylist.at(-1) // 'index2'

there are many methods in js that similarly do this, why using this new method?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Yes, there are similar ways to get an element from an array or string, but at() will use a clear and easy syntax to get this.

give an index and return value

the principle is easy, just put your desire index and get value, if there isn't a value at this index, it returns undefined

for examples:

const myList = ['index0', 'index1', 'index2']

// to get latest item in the list using common ways:
const latestItem = myList[ myList.length - 1]

// using simpler approach with at()
const latestItem = myList.at(-1)

similarly, at() method will work fine with strings.

  • at the writing time of this post, at() will not be supported by some browser, you can find this here.
  • you can use polyfill if you want to use at() method in your codebase.
about 4 years ago · Juan Pablo Isaza 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!