我想在比较两个数组后返回true或false。
此处为第一个数组:
const permissionsArray = [
{
"groupName": "User",
"permissions": [
"Permissions.Users.View",
"Permissions.Users.Create",
"Permissions.Users.Edit",
"Permissions.Users.Delete"
]
}, {
"groupName": "Role",
"permissions": [
"Permissions.Roles.View",
"Permissions.Roles.Create",
"Permissions.Roles.Edit",
"Permissions.Roles.Delete"
]
},
]
此处为包含权限的对象数组:
const userPermissionArray =
{
"id": "cdfda4d3-ea1a-4662-a611-2d2e52b772b0",
"name": "ABP Manager",
"description": "ABP Manager",
"usersCount": 4,
"isActive": false,
"permissions": [
"Permissions.Users.View",
"Permissions.Users.Create",
"Permissions.Users.Edit",
"Permissions.Users.Delete"
]
}
我希望比较**[权限数组.权限]和[用户权限数组.权限]**。
我试过了,但失败了。我的代码是:
console.log(
userPermissionArray.permissions
.map(roleItem => roleItem === userPermissionArray
.map(item => item.permissions.map(item => item))
)
);
我试图返回“真”或“假”。
3条答案
按热度按时间ruarlubt1#
您可以
flat
权限列表以便于比较,然后使用some
函数检查是否存在任何条目g2ieeal72#
试着这样比较:
iih3973s3#