I’m trying to declare an array of objects to add new objects later. I’m doing this away:
private arrayOfObjects: [{}];
When I try to push some object to it I receive the following error:
Cannot read property ‘push’ of undefined
I believe this is because the array needs to be initialized. If I initialize it like a normal array:
private arrayOfObjects: [{}] = [];
I get another error:
Property ‘0’ is missing in type ‘[ ]’ but required in type ‘[{}]’.
So if I declare the array this way:
private arrayOfObjects: [{}] = [{}];
I can now push objects to it, but I get an empty object in the beginning of the array. I can easily remove this object from the array, but I really want to know how I can do it correctly. I could not find any similar problem in here or in SO.
Object structure: {name: string, active: boolean}
So, how can I declare and initialize an array of objects without the empty object in it?