JavaScript Array keys() Tutorial

In this section, we will learn what the keys() method are and how to use them in JavaScript.

JavaScript Arrays keys() Method

The index numbers in JavaScript Arrays are known as the keys and they are used to reaching to elements of an array.

Now, with the help of keys() method, we can get all the keys of an array as well.

Array keys() Syntax:

array.keys()

Array keys() Method Parameters:

This method does not take an argument.

Array keys() Method Return Value:

The `keys()` method returns an iterator that contains the keys of the target array. The keys of an array are the numbers 0 to `target-array-length – 1`.

Example: using Array keys() method in JavaScript

const arr = ["Apple","Google","Microsoft","Amazon"];
for (const key of arr.keys()){
  console.log(key);
}

Output:

0

1

2

3
Facebook
Twitter
Pinterest
LinkedIn

Top Technologies