离子如何匹配数组中的单词

Ionic how to match a word in array

我的应用程序中有一个 policy_id 和数组列表,其中多个 policy_no 位于数组中。我需要从我拥有的数组中显示 policy_no 的数据。

我附上了我需要匹配数组中 policy_id 和 plicy_no 的图像,并仅显示该数组结果。

      this.policy_id = this.navParams.get('y'); // here is policy id
      console.log(this.policy_id);
      this.policies = this.navParams.get('z'); // here the policies array 
      console.log(this.policies);

您可以像这样过滤数组:

const policy_id = 'xxx';
const policies = [{ policy_no: 'xxx'}, { policy_no: 'yyy'}]
console.log(policies.filter((p) => p.policy_no === policy_id));
getRelatedPolicies(policy_id, policies) {
    return policies.filter(policy => policy.policy_no === policy_id);
}

From MDN:

The find() method returns a value in the array, if an element in the array satisfies the provided testing function. Otherwise undefined is returned.

 const police_id="abc";
 let res = policies.find(x => x.policy_no === police_id);