Navigate back to the homepage

How to define array of objects in typescript?

Infinitbility
TypeScript
March 29th, 2022 · 1 min read
keep affilitate

Hi Friends 👋,

Welcome to Infinitbility ❤️!

This tutorial is part of the below series.

TypeScript define variable

  1. How to define type in typescript?
  2. How to define array in typescript?
  3. How to define object in typescript?
  4. How to define array of objects in typescript?

Let start Part 3: How to define array of objects in typescript?

To create an array of objects, we will combine our Second and third tutorials, Here we have to define object property type and use it with in array data type.

Like

Array<ObjectType>

It also feels like custom data typing … ❤️.

So First we define object property type. like the below example.

1type User = {
2 id: int,
3 name: string;
4 isActive: boolean;
5};

And after that let tries to use it in the array.

1type User = {
2 id: int,
3 name: string;
4 isActive: boolean;
5};
6
7let users: Array<User> = [
8 {
9 id: 1,
10 name: "infintbility",
11 isActive: true
12 },
13 {
14 id: 2,
15 name: "aguidehub",
16 isActive: true
17 },
18];

When you follow, the above example you can easily understand what’s going on in it…

It’s end of TypeScript define variable series.

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.

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 define object in typescript?

TypeScript, create object example with data type.

March 28th, 2022 · 1 min read

How to define array in typescript?

TypeScript, create array example with diffrent data type.

March 27th, 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]