当前位置:网站首页>如何判断一个数组中的元素包含一个对象的所有属性值
如何判断一个数组中的元素包含一个对象的所有属性值
2022-07-06 16:46:00 【十月ooOO】
如何判断一个数组中的元素包含一个对象的所有属性值
问题描述
有下面这么一个对象模板,和基于这个对象模板产出的数组
// 对象模板
dataModel: {
name :"",
type :"",
ability :"",
activity :"",
ip :"",
manName :"",
manPwd :"",
modelName :"",
subCount :"",
},
// 数组数据
doorConfig: [
{
"ability": "BCP", "activity": true, "id": 0, "ip": "192.168.66.64", "manName": "admin", "manPwd": "haikang123", "modelName": "DS-K1T804BEF", "name": "东门门禁", "type": "一体机", "subCount": 0, "isEdit": false},
{
"ability": "BCPF", "activity": true, "id": 1, "ip": "192.168.66.3", "manName": "admin", "manPwd": "haikang123", "modelName": "DS-K1T671MF", "name": "西门门禁", "type": "一体机", "subCount": 0, "isEdit": false},
{
"ability": "BCPF", "activity": true, "id": 2, "ip": "192.168.66.3", "manName": "admin", "manPwd": "haikang123", "modelName": "DS-K1T671MF", "name": "南门门禁", "type": "一体机", "subCount": 0, "isEdit": false},
{
"ability": "BCPF", "activity": true, "id": 3, "ip": "192.168.66.3", "manName": "admin", "manPwd": "haikang123", "modelName": "DS-K1T671MF", "name": "北门门禁", "type": "一体机", "subCount": 0, "isEdit": false},
{
"ability": "BCPF", "activity": true, "id": 4, "ip": "192.168.66.3", "manName": "admin", "manPwd": "haikang123", "modelName": "DS-K1T671MF", "name": "主门门禁", "type": "一体机", "subCount": 0, "isEdit": false}
]
现在的状态是:
- 数组中每个对象的属性,对比对象模板可能会有缺失
- 数组中的对象属性,可能为空
现在需要实现功能是,根据这个对象模板,判断数组中
- 是否存在为空的字段
- 是否缺失某个属性
实现这个判断功能:
allPropertiesExist(){
// 1. 判断所有 doorConfig 元素是满足条件
return this.doorConfig.every(item => {
let allExist = true // 属性都存在的标识
// 2. 对每个 doorConfig 的数组元素判断
for (const label in this.dataModel){
// 3. 是否存在对象中的每个属性,属性是否为空
if (item.hasOwnProperty(label) && item[label] !== ''){
} else {
// 4. 任一一个属性不存在或为空时,就返回 false
allExist = false
}
}
return allExist
})
},
边栏推荐
- After leaving a foreign company, I know what respect and compliance are
- Supersocket 1.6 creates a simple socket server with message length in the header
- 1000 words selected - interface test basis
- 48 page digital government smart government all in one solution
- 微信小程序uploadfile服务器,微信小程序之wx.uploadFile[通俗易懂]
- 使用yum来安装PostgreSQL13.3数据库
- Leecode brush questions record sword finger offer 11 Rotate the minimum number of the array
- 1000字精选 —— 接口测试基础
- (leetcode) sum of two numbers
- Pinia module division
猜你喜欢
Business process testing based on functional testing
What is AVL tree?
DAY ONE
Interface joint debugging test script optimization v4.0
DAY TWO
MVC and MVVM
Designed for decision tree, the National University of Singapore and Tsinghua University jointly proposed a fast and safe federal learning system
pytest多进程/多线程执行测试用例
互动滑轨屏演示能为企业展厅带来什么
基於GO語言實現的X.509證書
随机推荐
System activity monitor ISTAT menus 6.61 (1185) Chinese repair
华为mate8电池价格_华为mate8换电池后充电巨慢
Racher integrates LDAP to realize unified account login
Why should a complete knapsack be traversed in sequence? Briefly explain
PostgreSQL highly available repmgr (1 master 2 slave +1witness) + pgpool II realizes master-slave switching + read-write separation
Typescript incremental compilation
js导入excel&导出excel
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
48页数字政府智慧政务一网通办解决方案
Leecode brush question record sword finger offer 58 - ii Rotate string left
App general function test cases
C语言输入/输出流和文件操作【二】
Use type aliases in typescript
【精品】pinia 基于插件pinia-plugin-persist的 持久化
pytest多进程/多线程执行测试用例
17、 MySQL - high availability + read / write separation + gtid + semi synchronous master-slave replication cluster
《LaTex》LaTex数学公式简介「建议收藏」
St table
[boutique] Pinia Persistence Based on the plug-in Pinia plugin persist
Core knowledge of distributed cache