当前位置:网站首页>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
})
},
边栏推荐
- Cross-entrpy Method
- Why should a complete knapsack be traversed in sequence? Briefly explain
- 英雄联盟|王者|穿越火线 bgm AI配乐大赛分享
- DAY FIVE
- 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
- What is a responsive object? How to create a responsive object?
- File and image comparison tool kaleidoscope latest download
- 2022/2/10 summary
- Data analysis course notes (III) array shape and calculation, numpy storage / reading data, indexing, slicing and splicing
- @TableId can‘t more than one in Class: “com.example.CloseContactSearcher.entity.Activity“.
猜你喜欢

VTK volume rendering program design of 3D scanned volume data

什么是响应式对象?响应式对象的创建过程?

沉浸式投影在线下展示中的三大应用特点

48页数字政府智慧政务一网通办解决方案

Racher integrates LDAP to realize unified account login

@TableId can‘t more than one in Class: “com.example.CloseContactSearcher.entity.Activity“.

Designed for decision tree, the National University of Singapore and Tsinghua University jointly proposed a fast and safe federal learning system

Core knowledge of distributed cache

【2022全网最细】接口测试一般怎么测?接口测试的流程和步骤

【vulnhub】presidential1
随机推荐
[CVPR 2022] semi supervised object detection: dense learning based semi supervised object detection
Google, Baidu and Yahoo are general search engines developed by Chinese companies_ Baidu search engine URL
Policy Gradient Methods
How can computers ensure data security in the quantum era? The United States announced four alternative encryption algorithms
js导入excel&导出excel
一图看懂对程序员的误解:西方程序员眼中的中国程序员
Operation test of function test basis
Testers, how to prepare test data
Common shortcuts to idea
Use source code compilation to install postgresql13.3 database
Racher integrates LDAP to realize unified account login
[boutique] Pinia Persistence Based on the plug-in Pinia plugin persist
Value Function Approximation
Amazon MemoryDB for Redis 和 Amazon ElastiCache for Redis 的内存优化
沉浸式投影在线下展示中的三大应用特点
Oracle EMCC 13.5 environment in docker every minute
vector的使用方法_vector指针如何使用
SQL的一种写法,匹配就更新,否则就是插入
What is web penetration testing_ Infiltration practice
如何判断一个数组中的元素包含一个对象的所有属性值