男儿欲遂平生志,六经勤向窗前读。这篇文章主要讲述如何判断一个数组中的元素包含一个对象的所有属性值相关的知识,希望能为你提供帮助。
如何判断一个数组中的元素包含一个对象的所有属性值问题描述【如何判断一个数组中的元素包含一个对象的所有属性值】
有下面这么一个对象模板,和基于这个对象模板产出的数组
// 对象模板
dataModel:
name:"",
type:"",
ability:"",
activity:"",
ip:"",
manName:"",
manPwd:"",
modelName :"",
subCount:"",
,
// 数组数据
doorConfig: [
"ability": "BCP", "activity": true, "id": 0, "ip": "192.168.66.64", "manName": "admin", "manPwd": "haikang123", "modelName": "DS-K1T804BEF", "name": "东门门禁", "type": "一体机", "subCount": 0, "isEdit": false,
"ability": "BCPF", "activity": true, "id": 1, "ip": "192.168.66.3", "manName": "admin", "manPwd": "haikang123", "modelName": "DS-K1T671MF", "name": "西门门禁", "type": "一体机", "subCount": 0, "isEdit": false,
"ability": "BCPF", "activity": true, "id": 2, "ip": "192.168.66.3", "manName": "admin", "manPwd": "haikang123", "modelName": "DS-K1T671MF", "name": "南门门禁", "type": "一体机", "subCount": 0, "isEdit": false,
"ability": "BCPF", "activity": true, "id": 3, "ip": "192.168.66.3", "manName": "admin", "manPwd": "haikang123", "modelName": "DS-K1T671MF", "name": "北门门禁", "type": "一体机", "subCount": 0, "isEdit": false,
"ability": "BCPF", "activity": true, "id": 4, "ip": "192.168.66.3", "manName": "admin", "manPwd": "haikang123", "modelName": "DS-K1T671MF", "name": "主门门禁", "type": "一体机", "subCount": 0, "isEdit": false
]
现在的状态是:
现在需要实现功能是,根据这个对象模板,判断数组中
实现这个判断功能:
allPropertiesExist()
// 1. 判断所有 doorConfig 元素是满足条件
return this.doorConfig.every(item =>
let allExist = true // 属性都存在的标识
// 2. 对每个 doorConfig 的数组元素判断
for (const label in this.dataModel)
// 3. 是否存在对象中的每个属性,属性是否为空
if (item.hasOwnProperty(label) &
&
item[label] !== )
else
// 4. 任一一个属性不存在或为空时,就返回 false
allExist = false
return allExist
)
,
推荐阅读
- RationalDMIS2022阵列工件测量
- CentOS 如何安装 Nginx
- adb install 安装apk时报错Failure [INSTALL_FAILED_TEST_ONLY]解决方法
- Pod 安全策略
- K8S系列Kubernetes简介
- kubernetes RBAC相遇--介绍常规用法集群默认
- java微信小程序的电动汽车充电桩服务平台源码介绍
- Oracle-表空间管理
- 运维之思科篇 -----1.VLANTrunk以太通道及DHCP