by @saigowthamr

How to get number of keys in JavaScript object

Home » javascript » How to get number of keys in JavaScript object

To get the number of keys we can use the Object.keys() method in JavaScript.

Example:

const obj = {
    name: 'king',
    age: 20,
    active: true
}

console.log(Object.keys(obj).length); // 3