Reputation: 832
How to get the length of an object array object in angular.
Here's the code:
list.component.ts
const obj: any = {};
this.days.forEach((x: any) => {
const itemFilter = this.rowData.filter((item: any) => item);
itemFilter.forEach((item: any) => {
const date = format(item.lastpmdate, 'YYYY-MM-DD');
if (format(x.date, 'YYYY-MM-DD') === date) {
if (obj[date]) {
obj[date].push(item);
} else {
obj[date] = [item];
}
}
});
});
What I need is to get the length of the object array.
Thanks in advance.
Upvotes: 0
Views: 5186
Reputation: 10820
You can list the keys of the target object with Object.keys
and then check its length as a normal array:
Object.keys(this.days).length
If you have an object of arrays:
Object.values(this.days).map(v => v.length)
Object.values() allows to iterate over the object values instead of the keys.
Having these, you can then get the length for each of the inner arrays.
Upvotes: 1