Home » JavaScript Array entries() Method

JavaScript Array entries() Method

by Online Tutorials Library

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.

Test it Now

Output:

The output shows the elements of the array with key assigned to it. Thus, together forms a key/value pair.

JavaScript Array entries() Method

Example2: This example represents the array entries() method through let declaration.

Test it Now

Output:

The output will be same as shown in the above example.

JavaScript Array entries() Method

Example3: This example displays the (key,value) pairs of the array by clicking on the “apply” button.

Test it Now

Output:

After calling the arr() function, the output comes out:

JavaScript Array entries() Method

Example4: Displaying the position of the candidates in the given array.

Test it Now

Output:

The output will be:

JavaScript Array entries() Method

Example5:

Test it Now

Output:

After clicking on the “display” button, the position of each number in the array will be:

JavaScript Array entries() Method


Next TopicJavaScript Array

You may also like