JavaScript Object keys() function | Get keys of object

  • by

JavaScript Object keys() method returns an array of a given object’s own enumerable property names. The ordering of the properties is the same as that given by the object manually in a loop applied to the properties.

Object.keys(obj)

JavaScript object keys

A simple example code gets all keys of a given object.

<!DOCTYPE html>
<html>
<body>

  <script>

    var obj = {name: "Martin", age: 30, city: "United States"};
    let res = Object.keys(obj);

    console.log(res);

  </script>

</body>
</html> 

Output:

JavaScript Object keys() function get keys of object

Do comment if you have any doubts or suggestions on this Js Object key topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.