I am currently utilizing Angular 5 with typescript version 2.7.1. Within typescript, I have created a custom type:
arr: {id: string; name: string; }[];
I am attempting to add an element to the array and have experimented with the following methods:
this.arr.push({id: "text", name: "text"})
However, I encountered the following error: TypeError: Cannot read property 'push' of undefined
let array2 : {id: "id", name: "name"}
this.arr.push(array2)
Again, I received the same error message: TypeError: Cannot read property 'push' of undefined
I am puzzled as to why this is not functioning as expected. I am clearly defining id and name within the push operation. Can anyone provide insight into what I might be missing?