根据内部值重建数组

时间:2018-08-30 07:25:11

标签: angular typescript

我有以下数组

[
  {
    "dn": "cn=GAU200900LD01,cn=Workstations,ou=200900,ou=GAU,o=firstrand,c=za",
    "name": "GAU200900LD01",
    "mac_address": "00:24:1D:AF:D2:84",
    "address": "10.34.102.2",
    "image": "scImageFile=FNBSALES,cn=default,cn=global,o=firstrand,c=za"
  },
  {
    "dn": "cn=GAU200900LD02,cn=Workstations,ou=200900,ou=GAU,o=firstrand,c=za",
    "name": "GAU200900LD02",
    "mac_address": "00:24:1D:AF:D2:23",
    "address": "10.34.102.3",
    "image": "scImageFile=FNBSALES,cn=default,cn=global,o=firstrand,c=za"
  },
  {
    "dn": "cn=GAU200900LD03,cn=Workstations,ou=200900,ou=GAU,o=firstrand,c=za",
    "name": "GAU200900LD03",
    "mac_address": "00:24:1D:AF:DB:8B",
    "address": "10.34.102.4",
    "image": "scImageFile=FNBSALES,cn=default,cn=global,o=firstrand,c=za"
  },
  {
    "dn": "cn=GAU555555LD01,cn=Workstations,ou=555555,ou=GAU,o=firstrand,c=za",
    "name": "GAU555555LD01",
    "mac_address": "00:00:00:00:00:00",
    "address": "10.0.0.2",
    "image": "cn=Ubuntu,cn=default,cn=global,o=firstrand,c=za"
  }
]

我正在尝试去除ou值与特定值不匹配的所有对象,例如。 ou = 200900。所以我不想让我的数组包含ou = 555555

1 个答案:

答案 0 :(得分:1)

您可以使用indexOf和过滤器来实现此功能,例如:

const result = objects.filter(object => object.dn.indexOf('200900')> 0);

const result = objects.filter(object => object.dn.indexOf('ou = 200900')> 0);

console.log(result);