Navigate back to the homepage

how to get length of object in typescript?

Infinitbility
TypeScript
July 28th, 2022 · 1 min read
how to get length of object in typescript?

Get the length of the object in typescript

To get the length of the object in typescript, you can use the Object.keys() method with the length property it will return the length of the object.

1// ✅ Get the length of the object in typescript
2let num: number = 493054;
3Object.keys({id: 1, name: "infinitbility.com"}).length;
4// 👉️ 2

Today, I’m going to show you How do I get the length of the object in typescript, as above mentioned here, I’m going to use theObject.keys() method with the length property to get the length of objects;

Let’s start today’s tutorial how do you get the length of the object in typescript?

First, I will take the sample object variable with sample data, then I will use Object.keys() to get an array of keys and use the length property, let’s console it.

1// ✅ Get the length of the object in typescript
2
3interface domain {
4 id: number,
5 name: string
6}
7
8let obj: domain = {id: 1, name: "infinitbility.com"};
9let lenOfObj: number = Object.keys(obj).length;
10console.log(lenOfObj)
11// 👉️ 2

I hope it helps you, All the best 👍.

Follow me on Twitter

Join our email list and get notified about new content

No worries, I respect your privacy and I will never abuse your email.

Every week, on Tuesday, you will receive a list of free tutorials I made during the week (I write one every day) and news on other training products I create.

Looking For React Native Tutorial?

we are trying to create the best Tutorial for react native developers.

When you want a daily updates about React Native Tutorial or infinitbility update subscribe to our newsletter.

Read React Native Tutorial

Request New Tutorial or Article on mail [email protected]

Guide book

Guidebook: The Javascript Monorepo Photoshop Guide

Tutorials

Categories

More articles from Infinitbility

how to add number to string in typescript?

how to add number to string in typescript?

TypeScript, convert array to string example with a step-by-step guide.

July 27th, 2022 · 1 min read
how to call script type module function in javascript?

how to call script type module function in javascript?

An example of call script type module function in javascript with step by step guide.

July 26th, 2022 · 1 min read
© 2020–2022 Infinitbility
About
Link to $https://medium.com/infinitbilityLink to $https://www.facebook.com/InfinitbilityLink to $https://github.com/infinitbilityLink to $https://twitter.com/infinitbilityLink to $https://www.buymeacoffee.com/infinitbilityLink to $mailto:[email protected]