I have an array called "cart" of objects which looks like this,
cart:[{name:any, rate:number, qty:number, discount:number, subtotal:number}]
and I don't want to have any data in it at the beginning, but when I write
cart:[{name:any, rate:number, qty:number, discount:number, subtotal:number}];
and try to find the length by using
Object.keys(this.cart).length
it shows an error saying
`TypeError: Cannot convert undefined or null to object`
Also, how to clear all elements in an Array.
Based on my understanding, the following should work for you,
interface ISomething {
name: any;
rate: number;
qty: number;
discount: number;
subtotal: number
}
let cart: Array<ISomething> = [];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With