当前位置:网站首页>如何判断一个数组中的元素包含一个对象的所有属性值
如何判断一个数组中的元素包含一个对象的所有属性值
2022-07-06 16:46:00 【十月ooOO】
如何判断一个数组中的元素包含一个对象的所有属性值
问题描述
有下面这么一个对象模板,和基于这个对象模板产出的数组
// 对象模板
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
})
},
边栏推荐
- How about the order management of okcc call center
- Building lease management system based on SSM framework
- Core knowledge of distributed cache
- How to answer the dualistic opposition of Zhihu
- Leecode brush questions record sword finger offer 11 Rotate the minimum number of the array
- 2022 latest blind box mall complete open source operation source code / docking visa free payment interface / building tutorial
- DAY FIVE
- Leecode brush question record sword finger offer 56 - ii Number of occurrences of numbers in the array II
- Command line kills window process
- Leecode brush questions record sword finger offer 43 The number of occurrences of 1 in integers 1 to n
猜你喜欢
After leaving a foreign company, I know what respect and compliance are
ldap创建公司组织、人员
48 page digital government smart government all in one solution
2022 latest blind box mall complete open source operation source code / docking visa free payment interface / building tutorial
App general function test cases
File and image comparison tool kaleidoscope latest download
专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
互动滑轨屏演示能为企业展厅带来什么
Rider离线使用Nuget包的方法
2022 PMP project management examination agile knowledge points (9)
随机推荐
48页数字政府智慧政务一网通办解决方案
MySQL master-slave multi-source replication (3 master and 1 slave) setup and synchronization test
JWT signature does not match locally computed signature. JWT validity cannot be asserted and should
陀螺仪的工作原理
Random类的那些事
【CVPR 2022】半监督目标检测:Dense Learning based Semi-Supervised Object Detection
在Docker中分分钟拥有Oracle EMCC 13.5环境
Imeta | Chen Chengjie / Xia Rui of South China Agricultural University released a simple method of constructing Circos map by tbtools
Clipboard management tool paste Chinese version
Encryption algorithm - password security
DAY FOUR
从外企离开,我才知道什么叫尊重跟合规…
Tourism Management System Based on jsp+servlet+mysql framework [source code + database + report]
Geo data mining (III) enrichment analysis of go and KEGG using David database
Operation test of function test basis
37页数字乡村振兴智慧农业整体规划建设方案
基于jsp+servlet+mysql框架的旅游管理系统【源码+数据库+报告】
【自动化测试框架】关于unittest你需要知道的事
1000字精选 —— 接口测试基础
What is web penetration testing_ Infiltration practice