当前位置:网站首页>如何判断一个数组中的元素包含一个对象的所有属性值
如何判断一个数组中的元素包含一个对象的所有属性值
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
})
},
边栏推荐
- Use source code compilation to install postgresql13.3 database
- Rails 4 asset pipeline vendor asset images are not precompiled
- SQL的一种写法,匹配就更新,否则就是插入
- 基于SSM框架实现的房屋租赁管理系统
- Supersocket 1.6 creates a simple socket server with message length in the header
- 37頁數字鄉村振興智慧農業整體規劃建設方案
- [CVPR 2022] target detection sota:dino: Detr with improved detecting anchor boxes for end to end object detection
- 一图看懂对程序员的误解:西方程序员眼中的中国程序员
- Designed for decision tree, the National University of Singapore and Tsinghua University jointly proposed a fast and safe federal learning system
- Jenkins' user credentials plug-in installation
猜你喜欢

iMeta | 华南农大陈程杰/夏瑞等发布TBtools构造Circos图的简单方法

Introduction to GPIO

509 certificat basé sur Go

工程师如何对待开源 --- 一个老工程师的肺腑之言

1000 words selected - interface test basis

基于jsp+servlet+mysql框架的旅游管理系统【源码+数据库+报告】

app通用功能測試用例

Pytest multi process / multi thread execution test case

48 page digital government smart government all in one solution

What is AVL tree?
随机推荐
互动滑轨屏演示能为企业展厅带来什么
DAY THREE
[vector retrieval research series] product introduction
kubernetes部署ldap
Typescript incremental compilation
Three sentences to briefly introduce subnet mask
Leecode brush questions record sword finger offer 43 The number of occurrences of 1 in integers 1 to n
[2022 the finest in the whole network] how to test the interface test generally? Process and steps of interface test
SuperSocket 1.6 创建一个简易的报文长度在头部的Socket服务器
在Docker中分分钟拥有Oracle EMCC 13.5环境
2022 latest blind box mall complete open source operation source code / docking visa free payment interface / building tutorial
VTK volume rendering program design of 3D scanned volume data
(leetcode) sum of two numbers
iMeta | 华南农大陈程杰/夏瑞等发布TBtools构造Circos图的简单方法
Leecode brushes questions to record interview questions 17.16 massagist
2022年PMP项目管理考试敏捷知识点(9)
Pdf document signature Guide
okcc呼叫中心的订单管理时怎么样的
【CVPR 2022】目标检测SOTA:DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection
Data operation platform - data collection [easy to understand]