How to get the object length in TypeScript?

Sometimes, we want to get the object length in TypeScript.

In this article, we’ll look at how to get the object length in TypeScript.

How to get the object length in TypeScript?

To get the object length in TypeScript, we can use the Object.keys method and the array length property.

For instance, we write

Object.keys(customer).length;

to return an array of non-inherited keys from the customer object with Object.keys.

Then we get the length of the array with length.

Conclusion

To get the object length in TypeScript, we can use the Object.keys method and the array length property.