当前位置:网站首页>如何判断一个数组中的元素包含一个对象的所有属性值
如何判断一个数组中的元素包含一个对象的所有属性值
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
})
},
边栏推荐
- A way of writing SQL, update when matching, or insert
- rancher集成ldap,实现统一账号登录
- [automated testing framework] what you need to know about unittest
- The programmer resigned and was sentenced to 10 months for deleting the code. Jingdong came home and said that it took 30000 to restore the database. Netizen: This is really a revenge
- DAY SIX
- 在docker中快速使用各个版本的PostgreSQL数据库
- [2022 the finest in the whole network] how to test the interface test generally? Process and steps of interface test
- Tourism Management System Based on jsp+servlet+mysql framework [source code + database + report]
- Racher integrates LDAP to realize unified account login
- 【CVPR 2022】半监督目标检测:Dense Learning based Semi-Supervised Object Detection
猜你喜欢

Introduction to GPIO

After leaving a foreign company, I know what respect and compliance are

陀螺仪的工作原理

DAY FIVE
![[2022 the finest in the whole network] how to test the interface test generally? Process and steps of interface test](/img/8d/b59cf466031f36eb50d4d06aa5fbe4.jpg)
[2022 the finest in the whole network] how to test the interface test generally? Process and steps of interface test

2022 latest blind box mall complete open source operation source code / docking visa free payment interface / building tutorial

基於GO語言實現的X.509證書

uniapp实现从本地上传头像并显示,同时将头像转化为base64格式存储在mysql数据库中

DAY FOUR

基于SSM框架实现的房屋租赁管理系统
随机推荐
After leaving a foreign company, I know what respect and compliance are
【CVPR 2022】半监督目标检测:Dense Learning based Semi-Supervised Object Detection
Cas d'essai fonctionnel universel de l'application
What is web penetration testing_ Infiltration practice
Building lease management system based on SSM framework
使用源码编译来安装PostgreSQL13.3数据库
基于SSM框架实现的房屋租赁管理系统
(leetcode) sum of two numbers
Use type aliases in typescript
数据运营平台-数据采集[通俗易懂]
准备好在CI/CD中自动化持续部署了吗?
37页数字乡村振兴智慧农业整体规划建设方案
Supersocket 1.6 creates a simple socket server with message length in the header
openresty ngx_ Lua subrequest
三句话简要介绍子网掩码
What can the interactive slide screen demonstration bring to the enterprise exhibition hall
A way of writing SQL, update when matching, or insert
【向量检索研究系列】产品介绍
Close unregistering application XXX with Eureka with status down after Eureka client starts
2022/2/11 summary