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

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

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 Relatório

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 Relatório

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 Relatório

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