Categories
TypeScript Answers

How to get the object length in TypeScript?

Spread the love

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.

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 *