当前位置:网站首页>如何判断一个数组中的元素包含一个对象的所有属性值
如何判断一个数组中的元素包含一个对象的所有属性值
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
})
},
边栏推荐
- 【CVPR 2022】目标检测SOTA:DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection
- Personal digestion of DDD
- 1000 words selected - interface test basis
- [vector retrieval research series] product introduction
- 三维扫描体数据的VTK体绘制程序设计
- 准备好在CI/CD中自动化持续部署了吗?
- 沉浸式投影在线下展示中的三大应用特点
- Leecode brush question record sword finger offer 56 - ii Number of occurrences of numbers in the array II
- How can computers ensure data security in the quantum era? The United States announced four alternative encryption algorithms
- 从外企离开,我才知道什么叫尊重跟合规…
猜你喜欢

准备好在CI/CD中自动化持续部署了吗?

刘永鑫报告|微生物组数据分析与科学传播(晚7点半)

37页数字乡村振兴智慧农业整体规划建设方案

AVL树到底是什么?

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

Imeta | Chen Chengjie / Xia Rui of South China Agricultural University released a simple method of constructing Circos map by tbtools

从外企离开,我才知道什么叫尊重跟合规…

What is a responsive object? How to create a responsive object?

GPIO简介

Three application characteristics of immersive projection in offline display
随机推荐
Building lease management system based on SSM framework
ldap创建公司组织、人员
GPIO簡介
基於GO語言實現的X.509證書
2022/2/11 summary
Wind chime card issuing network source code latest version - commercially available
Imeta | Chen Chengjie / Xia Rui of South China Agricultural University released a simple method of constructing Circos map by tbtools
GEO数据挖掘(三)使用DAVID数据库进行GO、KEGG富集分析
智能运维应用之道,告别企业数字化转型危机
使用yum来安装PostgreSQL13.3数据库
Leecode brush questions record sword finger offer 11 Rotate the minimum number of the array
DAY FIVE
Core knowledge of distributed cache
2022 PMP project management examination agile knowledge points (9)
2022 latest blind box mall complete open source operation source code / docking visa free payment interface / building tutorial
File and image comparison tool kaleidoscope latest download
Pdf document signature Guide
DAY THREE
2022/2/12 summary
rancher集成ldap,实现统一账号登录