当前位置:网站首页>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
})
},
边栏推荐
- AI超清修复出黄家驹眼里的光、LeCun大佬《深度学习》课程生还报告、绝美画作只需一行代码、AI最新论文 | ShowMeAI资讯日报 #07.06
- Amazon MemoryDB for Redis 和 Amazon ElastiCache for Redis 的内存优化
- What is web penetration testing_ Infiltration practice
- Designed for decision tree, the National University of Singapore and Tsinghua University jointly proposed a fast and safe federal learning system
- DAY TWO
- Are you ready to automate continuous deployment in ci/cd?
- 【vulnhub】presidential1
- JS import excel & Export Excel
- vector的使用方法_vector指针如何使用
- kubernetes部署ldap
猜你喜欢
@TableId can‘t more than one in Class: “com.example.CloseContactSearcher.entity.Activity“.
What is AVL tree?
Interface master v3.9, API low code development tool, build your interface service platform immediately
Core knowledge of distributed cache
On February 19, 2021ccf award ceremony will be held, "why in Hengdian?"
2022/2/12 summary
Amazon MemoryDB for Redis 和 Amazon ElastiCache for Redis 的内存优化
AI超清修复出黄家驹眼里的光、LeCun大佬《深度学习》课程生还报告、绝美画作只需一行代码、AI最新论文 | ShowMeAI资讯日报 #07.06
一图看懂对程序员的误解:西方程序员眼中的中国程序员
GEO数据挖掘(三)使用DAVID数据库进行GO、KEGG富集分析
随机推荐
2022/2/12 summary
Huawei mate8 battery price_ Huawei mate8 charges very slowly after replacing the battery
openresty ngx_ Lua subrequest
Personal digestion of DDD
Pdf document signature Guide
What is AVL tree?
Leecode brush questions record sword finger offer 11 Rotate the minimum number of the array
509 certificat basé sur Go
PostgreSQL uses pgpool II to realize read-write separation + load balancing
DAY ONE
Leecode brushes questions and records interview questions 01.02 Determine whether it is character rearrangement for each other
Interface master v3.9, API low code development tool, build your interface service platform immediately
2022/2/10 summary
Sword finger offer 26 Substructure of tree
How to use vector_ How to use vector pointer
DAY TWO
[automated testing framework] what you need to know about unittest
VTK volume rendering program design of 3D scanned volume data
C语言输入/输出流和文件操作【二】
Building lease management system based on SSM framework