当前位置:网站首页>How to judge whether an element in an array contains all attribute values of an object
How to judge whether an element in an array contains all attribute values of an object
2022-07-07 00:33:00 【October oooo】
How to judge whether the elements in an array contain all the attribute values of an object
Problem description
There is such an object template , And an array based on this object template
// Object templates
dataModel: {
name :"",
type :"",
ability :"",
activity :"",
ip :"",
manName :"",
manPwd :"",
modelName :"",
subCount :"",
},
// Array data
doorConfig: [
{
"ability": "BCP", "activity": true, "id": 0, "ip": "192.168.66.64", "manName": "admin", "manPwd": "haikang123", "modelName": "DS-K1T804BEF", "name": " East Gate access control ", "type": " Integrated machine ", "subCount": 0, "isEdit": false},
{
"ability": "BCPF", "activity": true, "id": 1, "ip": "192.168.66.3", "manName": "admin", "manPwd": "haikang123", "modelName": "DS-K1T671MF", "name": " West gate access control ", "type": " Integrated machine ", "subCount": 0, "isEdit": false},
{
"ability": "BCPF", "activity": true, "id": 2, "ip": "192.168.66.3", "manName": "admin", "manPwd": "haikang123", "modelName": "DS-K1T671MF", "name": " South gate access control ", "type": " Integrated machine ", "subCount": 0, "isEdit": false},
{
"ability": "BCPF", "activity": true, "id": 3, "ip": "192.168.66.3", "manName": "admin", "manPwd": "haikang123", "modelName": "DS-K1T671MF", "name": " North gate access control ", "type": " Integrated machine ", "subCount": 0, "isEdit": false},
{
"ability": "BCPF", "activity": true, "id": 4, "ip": "192.168.66.3", "manName": "admin", "manPwd": "haikang123", "modelName": "DS-K1T671MF", "name": " Main door access ", "type": " Integrated machine ", "subCount": 0, "isEdit": false}
]
The present state is :
- The attributes of each object in the array , The template of the comparison object may be missing
- Object properties in the array , May is empty
The functions that need to be realized now are , According to this object template , In the array
- Whether there is an empty field
- Is an attribute missing
Realize this judgment function :
allPropertiesExist(){
// 1. Determine all doorConfig The element satisfies the condition
return this.doorConfig.every(item => {
let allExist = true // Identification of the existence of attributes
// 2. For each doorConfig Array element judgment
for (const label in this.dataModel){
// 3. Whether there are every attribute in the object , Whether the attribute is empty
if (item.hasOwnProperty(label) && item[label] !== ''){
} else {
// 4. When any attribute does not exist or is empty , Just go back to false
allExist = false
}
}
return allExist
})
},
边栏推荐
- 基于GO语言实现的X.509证书
- System activity monitor ISTAT menus 6.61 (1185) Chinese repair
- Leecode brush question record sword finger offer 58 - ii Rotate string left
- Use type aliases in typescript
- Encryption algorithm - password security
- File and image comparison tool kaleidoscope latest download
- How to use vector_ How to use vector pointer
- 三维扫描体数据的VTK体绘制程序设计
- Everyone is always talking about EQ, so what is EQ?
- GPIO简介
猜你喜欢
iMeta | 华南农大陈程杰/夏瑞等发布TBtools构造Circos图的简单方法
Jenkins' user credentials plug-in installation
DAY THREE
Imeta | Chen Chengjie / Xia Rui of South China Agricultural University released a simple method of constructing Circos map by tbtools
Interface master v3.9, API low code development tool, build your interface service platform immediately
DAY TWO
What is AVL tree?
1000 words selected - interface test basis
1000字精选 —— 接口测试基础
Data analysis course notes (III) array shape and calculation, numpy storage / reading data, indexing, slicing and splicing
随机推荐
Things like random
SQL的一种写法,匹配就更新,否则就是插入
Business process testing based on functional testing
Understand the misunderstanding of programmers: Chinese programmers in the eyes of Western programmers
Win10 startup error, press F9 to enter how to repair?
Command line kills window process
openresty ngx_ Lua subrequest
VTK volume rendering program design of 3D scanned volume data
Policy Gradient Methods
How engineers treat open source -- the heartfelt words of an old engineer
【向量检索研究系列】产品介绍
Three application characteristics of immersive projection in offline display
iMeta | 华南农大陈程杰/夏瑞等发布TBtools构造Circos图的简单方法
Introduction to GPIO
Use package FY in Oracle_ Recover_ Data. PCK to recover the table of truncate misoperation
Lombok 同时使⽤ @Data 和 @Builder 的坑,你中招没?
刘永鑫报告|微生物组数据分析与科学传播(晚7点半)
Testers, how to prepare test data
Notes of training courses selected by Massey school
Leecode brush questions record sword finger offer 11 Rotate the minimum number of the array