JavaScript Array entries() Method
The entries() method creates a new iterator object of an array, holding the key/value pairs for every value in the array. A key represents the index number carrying an item as its value. It does not affect the original array.
Syntax
The following syntax represents the entries() method:
Parameters
It does not have any parameters.
Return
It returns the newly created array iterator object. The iterator object represents each element of the array with keys assigned to them.
JavaScript Array entries() Method Examples
Let’s implement some examples to understand the toString() method better:
Example1: A simple array entries() method an array.
Output:
The output shows the elements of the array with key assigned to it. Thus, together forms a key/value pair.
Example2: This example represents the array entries() method through let declaration.
Output:
The output will be same as shown in the above example.
Example3: This example displays the (key,value) pairs of the array by clicking on the “apply” button.
Output:
After calling the arr() function, the output comes out:
Example4: Displaying the position of the candidates in the given array.
Output:
The output will be:
Example5:
Output:
After clicking on the “display” button, the position of each number in the array will be: