Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

408
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda