简体   繁体   English

如何以角度获取对象数组对象的长度

[英]How to get the length of an object array object in angular

How to get the length of an object array object in angular.如何以角度获取对象数组对象的长度。

Here's the code:这是代码:

list.component.ts列表.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.提前致谢。

You can list the keys of the target object with Object.keys and then check its length as a normal array:您可以使用Object.keys列出目标对象的键,然后检查其作为普通数组的长度:

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. Object.values() 允许迭代对象值而不是键。
Having these, you can then get the length for each of the inner arrays.有了这些,你就可以得到每个内部数组的长度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM