JavaScript Array .at() method

The JavaScript array .at() method is used to get one specific item in an array of items.

It requires one parameter which is an integer number that represents the index of an item in an array.

When the parameter is positive, it returns the value of that index. When the parameter is negative, it traverses from the end of the array until it finds the index of that negative integer.

Array .at() method using positive index


  const fruits = ['🍉', '🍍', '🍓', '🍌'];
  const fruitsAt = fruits.at(3);
  console.log(fruitsAt);

The output in the console would be:


  🍓

Array .at() method using negative index


  const fruits = ['🍉', '🍍', '🍓', '🍌'];
  const fruitsAt = fruits.at(-3);
  console.log(fruitsAt);

The console output would be:


  🍍

Watch Tutorial

Here's a quick video tutorial about the JavaScript array .at() method.