Get total number of keys in JavaScript object

Posted by I. B. Gd Pramana A. Putra, 18 Aug 22, last updated 18 Aug 22

You have a JavaScript object consisting of keys and values pair, how do you get the total number of keys in a JavaScript object?

const person = {"name": "Pramana", "role": "Engineer", "province": "Bali"};
const count_keys = Object.keys(my_object).length;




Notice that there are three keys inside our person object, those are name, role, and province.

I love sharing code snippets as most of the time, a quick code example is what we're looking for instead of long-written articles. If you think my code snippets are helpful and save you a lot of time, please consider buying me a cup of coffee :)

Support me via · paypal · buymeacoffee · ko-fi · trakteer
Contributed Snippets
Answer & Responses
    No comments yet

Wanna write a response?

You have to login before write a comment to this post.