Navigate back to the homepage

How to get array length in typescript?

Infinitbility
TypeScript
February 2nd, 2022 · 1 min read
keep affilitate

Hello Friends 👋,

Welcome To Infinitbility! ❤️

In TypeScript, create array has some different syntax because typescript supports static typing.

i.e when we create an array we have first what we will store in the array-like string, number, object, etc.

Today, we will learn how to create an array and how to check array length in typescript.

Let’s start with the creation

Now, we are going to create an array of objects then we have to provide Array<object> before storing data in variables like the below example.

1let exampleArr: Array<Object> = [
2 { id: 1, name: 'infinitbility' },
3 { id: 2, name: 'notebility' },
4 { id: 2, name: 'repairbility' },
5];

To check the length of the array we have the .length option to know the length of the array.

To find the length of exampleArr we have to write exampleArr.length and it will return 3.

1let exampleArr: Array<Object> = [
2 { id: 1, name: 'infinitbility' },
3 { id: 2, name: 'notebility' },
4 { id: 2, name: 'repairbility' },
5];
6
7exampleArr.length;

Output

typescript, array, length, example
TypeScript, get length of array example.

Thanks for reading…

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.

melio affilitate

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 key and value from json array object in javascript

Javascript, add key-value pair in json object example.

February 1st, 2022 · 1 min read

How to convert boolean to number in typescript?

TypeScript, convert boolean to number example.

January 31st, 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]