当前位置:网站首页>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
})
},
边栏推荐
- Use package FY in Oracle_ Recover_ Data. PCK to recover the table of truncate misoperation
- GEO数据挖掘(三)使用DAVID数据库进行GO、KEGG富集分析
- JS import excel & Export Excel
- Random类的那些事
- Designed for decision tree, the National University of Singapore and Tsinghua University jointly proposed a fast and safe federal learning system
- Amazon MemoryDB for Redis 和 Amazon ElastiCache for Redis 的内存优化
- 沉浸式投影在线下展示中的三大应用特点
- DAY THREE
- DAY FIVE
- How about the order management of okcc call center
猜你喜欢

DAY SIX

DAY TWO

How to set encoding in idea

如何判断一个数组中的元素包含一个对象的所有属性值

Imeta | Chen Chengjie / Xia Rui of South China Agricultural University released a simple method of constructing Circos map by tbtools

Win10 startup error, press F9 to enter how to repair?

准备好在CI/CD中自动化持续部署了吗?

What can the interactive slide screen demonstration bring to the enterprise exhibition hall

2022年PMP项目管理考试敏捷知识点(9)

工程师如何对待开源 --- 一个老工程师的肺腑之言
随机推荐
File and image comparison tool kaleidoscope latest download
微信小程序uploadfile服务器,微信小程序之wx.uploadFile[通俗易懂]
Racher integrates LDAP to realize unified account login
Command line kills window process
2022 PMP project management examination agile knowledge points (9)
GPIO简介
vector的使用方法_vector指针如何使用
Supersocket 1.6 creates a simple socket server with message length in the header
C language input / output stream and file operation [II]
Leecode brush questions record sword finger offer 43 The number of occurrences of 1 in integers 1 to n
uniapp实现从本地上传头像并显示,同时将头像转化为base64格式存储在mysql数据库中
英雄联盟|王者|穿越火线 bgm AI配乐大赛分享
Leecode brush questions record sword finger offer 44 A digit in a sequence of numbers
Use source code compilation to install postgresql13.3 database
[automated testing framework] what you need to know about unittest
JS import excel & Export Excel
Pdf document signature Guide
Leecode brush question record sword finger offer 56 - ii Number of occurrences of numbers in the array II
DAY FIVE
How about the order management of okcc call center