WebMasterCampus
WEB DEVELOPER Resources

Javascript Object Entries Method Loop Through Enumerable Properties

Learn how to use Javascript Object Entries Method to Loop Through Enumerable Properties


-Javascript Enumerable properties -Enumerable Properties Syntax -Example Of Object Keys

Javascript Enumerable Properties

Enumerable properties are those properties whose internal enumerable flag is set to true, which is the default for properties created via simple assignment or via a property initializer. Enumerable properties show up in for…in loops unless the property’s key is a Symbol.

The Object.entries() method returns an array of a given object’s own enumerable string-keyed property [key, value] pairs, in the same order as that provided by a for…in loop. (The only important difference is that a for…in loop enumerates properties in the prototype chain as well).

Enumerable Properties Syntax

 
 Object.entries(obj)

Object: The object whose own enumerable string-keyed property [key, value] pairs are to be returned.
Return value: An array of the given object’s own enumerable string-keyed property [key, value] pairs.

Example Of Object Keys

<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width">
</head>
<body>
  
  <div id="result"></div>
  
  <script>
     var pObject = {
        "key1": "value1",
        "key2": "value2",
        "key3": "value3"
    };


    for (let [key, value] of Object.entries(pObject)) {
      console.log('${key}: ${value}');
    }
  </script>

</body>
</html>
Created with love and passion.