如何在数组对象中查找数组

时间:2018-09-12 13:21:25

标签: arrays angular typescript object comparison

我有一个与此类似的数组

 export const PRIVILEGES: privileges[] =   [
  {
    Role: ['admin','trainer','trainee','designer'],
    Home: true,
    UserManagment:  true,
    DefineTraining:true,
   AssignTraining:  true ,
    AssignedTraining:  true,
    PerformanceAnalysis:  true
  },
  {
    Role: ['admin','trainee'],
    Home: true,
    UserManagment:  true,
    DefineTraining:false,
   AssignTraining:  false ,
    AssignedTraining:  true,
    PerformanceAnalysis: true
  }]

我的角色定义为

Role=['admin','trainee']

“我要获取角色与PRIVILEGES.Role匹配的PRIVILEGES的对象”

我尝试过

PRIVILEGES.find(x => x.Role == this.Role);

但这不会起作用,因为Role是一个数组,即使x.Role和this.Role都相同,它也会返回负结果。

0 个答案:

没有答案