当前位置:网站首页>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
})
},
边栏推荐
- 2021 SASE integration strategic roadmap (I)
- Google, Baidu and Yahoo are general search engines developed by Chinese companies_ Baidu search engine URL
- Command line kills window process
- 谷歌百度雅虎都是中国公司开发的通用搜索引擎_百度搜索引擎url
- 工程师如何对待开源 --- 一个老工程师的肺腑之言
- JWT signature does not match locally computed signature. JWT validity cannot be asserted and should
- 1000字精选 —— 接口测试基础
- 2022 PMP project management examination agile knowledge points (9)
- JS import excel & Export Excel
- Operation test of function test basis
猜你喜欢
随机推荐
Huawei mate8 battery price_ Huawei mate8 charges very slowly after replacing the battery
DAY FIVE
1000 words selected - interface test basis
GPIO简介
[boutique] Pinia Persistence Based on the plug-in Pinia plugin persist
量子时代计算机怎么保证数据安全?美国公布四项备选加密算法
Liuyongxin report | microbiome data analysis and science communication (7:30 p.m.)
48页数字政府智慧政务一网通办解决方案
Geo data mining (III) enrichment analysis of go and KEGG using David database
37 pages Digital Village revitalization intelligent agriculture Comprehensive Planning and Construction Scheme
2021 SASE integration strategic roadmap (I)
GEO数据挖掘(三)使用DAVID数据库进行GO、KEGG富集分析
Notes of training courses selected by Massey school
Leecode brushes questions and records interview questions 01.02 Determine whether it is character rearrangement for each other
互动滑轨屏演示能为企业展厅带来什么
What is a responsive object? How to create a responsive object?
Business process testing based on functional testing
GPIO簡介
PostgreSQL uses pgpool II to realize read-write separation + load balancing
MySQL主从之多源复制(3主1从)搭建及同步测试