JavaScript Array entries() Method

JavaScript Object.entries() method is used to return an array of a given object's own enumerable property [key, value] pairs. The ordering of the properties is the same as that given by looping over the property values of the object manually.

The entries() method returns an Array Iterator object with key/value pairs.

In JavaScript, entries() is an Array method that is used to return a new Array iterator object that allows you to iterate through the key/value pairs in the array. Because the entries() method is a method of the Array object, it must be invoked through a particular instance of the Array class.




Create an Array Iterator object, and create a loop that iterates each key/value pair:

var fruits = ["Banana", "Orange", "Apple", "Mango"];
var f = fruits.entries();

for (x of f) {
  document.getElementById("demo").innerHTML += x;

Example -