Categories
JavaScript Answers

How to count a JavaScript object’s attributes?

Spread the love

Sometimes, we want to count a JavaScript object’s attributes.

In this article, we’ll look at how to count a JavaScript object’s attributes.

How to count a JavaScript object’s attributes?

To count a JavaScript object’s attributes, we can use the Object.keys method.

For instance, we write

Object.keys(myObject).length;

to call Object.keys with myObject to get an array of non-inherited property keys in myObject.

Then we use the length property to get the number of properties in myObject.

Conclusion

To count a JavaScript object’s attributes, we can use the Object.keys method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *