Categories
JavaScript Answers

How to get object property name with JavaScript?

Spread the love

Sometimes, we want to get object property name with JavaScript.

In this article, we’ll look at how to get object property name with JavaScript.

How to get object property name with JavaScript?

To get object property name with JavaScript, we use the Object.keys method.

For instance, we write

const result = Object.keys(myVar);
console.log(result[0]);

to call Object.keys with myVar to return an array of property key strings in the myVar object.

Then we get the first key from the array with result[0].

Conclusion

To get object property name with JavaScript, we use the Object.keys method.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.