Hi Friends đź‘‹,

Welcome to Infinitbility ❤️!

This tutorial is part of the below series.

TypeScript define variable

How to define type in typescript?

How to define array in typescript?

How to define object in typescript?

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.

type User = {
    id: int,
    name: string;
    isActive: boolean;
};

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

type User = {
    id: int,
    name: string;
    isActive: boolean;
};

let users: Array<User> = [
    {
        id: 1,
        name: "infintbility",
        isActive: true
    },
    {
        id: 2,
        name: "aguidehub",
        isActive: true
    },
];

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 đź‘Ť.