Home > OS >  Angular - declare and initialize array inside an object
Angular - declare and initialize array inside an object

Time:06-26

I am trying to declare an array inside an object as follows:

data = {
    arr: [],
}

However, I want also to declare the type of each element in the array, i.e. something like:

data = {
    arr: any = [],
}

I have not find the way to do this. Can't I declare the type too?

Thanks a lot.

CodePudding user response:

You define the type of the object, containing a key arr which is an array of type any (although it should not be any, but you add your typing there )

const data: { arr: any[] } = { arr: [] };
  • Related