当前位置:网站首页>every()、map()、forEarch()方法。数组里面有对象的情况
every()、map()、forEarch()方法。数组里面有对象的情况
2022-06-24 07:06:00 【隐密修罗】
every()方法
这个是数组和对象:
方法用于检测数组所有元素是否都符合指定条件(通过函数提供)。
every() 方法使用指定函数检测数组中的所有元素:
如果数组中检测到有一个元素不满足,则整个表达式返回 false ,且剩余的元素不会再进行检测。
如果所有元素都满足条件,则返回 true。
注意: every() 不会对空数组进行检测。
注意: every() 不会改变原始数组。
<template>
<button @click="chooseButton(index)" :class="item.myShow===true?'collectTwo' : 'my_choose'" ></button>
</template>
export default{
data(){
return{
collestList:[
{
myshow:false
},
{
myshow:false
},
{
myshow:false
}
]
}
}
method:{
// 选中的项
chooseButton:function(res){
// 判断是否全部选中了
let myselse = this.collestList.every(item=>{
if (item.myShow==true) return true })
console.log(myselse)//输出为false
},
}
}

map()方法
作用:通过指定函数对数组进行处理,并将处理后的结果以新数组的形式返回
注意点:不会改变原数组,只是将处理后的结果以新数组的形式返回
var users = [
{
name: "张含韵", "email": "[email protected]"},
{
name: "江一燕", "email": "[email protected]"},
{
name: "李小璐", "email": "[email protected]"}
];
var emails = users.map(function (user) {
return user.email; });
console.log(emails);
//["[email protected]", "[email protected]", "[email protected]"]
forEach() 方法
forEach() 方法用于调用数组的每个元素,并将元素传递给回调函数。
注意: forEach() 对于空数组是不会执行回调函数的。
this.collestList.forEach((value , index) => {
///这是在collestList里面添加myShow:false 的字段
value['myShow1'] = false
})
///变成这样的
collestList:[
{
myshow:false,
myshow1:false
},
{
myshow:false,
myshow1:false
},
{
myshow:false,
myshow1:false
}
]
边栏推荐
- Numpy 中的方法汇总
- 利用sonar做代码检查
- Tencent cloud ASR product PHP realizes real-time voice authentication request
- Using sonar for code checking
- ZUCC_编译语言原理与编译_实验06 07 语法分析 LL 分析
- Common misconceptions in Tencent conference API - signature error_ code 200003
- 5 minutes, excellent customer service chat handling skills
- 表单图片上传在Chorme中无法查看请求体的二进制图片信息
- Redis cluster data skew
- 利用ngrok做内网穿透
猜你喜欢

Jenkins自动化部署,连接不到所依赖的服务【已解决】
![打印出来的对象是[object object],解决方法](/img/fc/9199e26b827a1c6304fcd250f2301e.png)
打印出来的对象是[object object],解决方法

New technology practice, encapsulating the permission application library step by step with the activity results API

疫情、失业,2022,我们高喊着摆烂和躺平!
![[team management] 25 tips for testing team performance management](/img/bd/0ef55630de43efcf5aa663f3099fce.jpg)
[team management] 25 tips for testing team performance management

liunx服务器 telnet 带用户名 端口登陆方法

【关于运维和网工的差别,一文说透】

教程篇(5.0) 08. Fortinet安全架构集成与FortiXDR * FortiEDR * Fortinet 网络安全专家 NSE 5

關於ETL看這篇文章就够了,三分鐘讓你明白什麼是ETL

pymysql 向MySQL 插入数据无故报错
随机推荐
Rescue system -- the application of read-write separation
lombok 使用
RuntimeError: Missing dependencies:XXX
Pymysql inserts data into MySQL and reports an error for no reason
js中通过key查找和更新对象中指定值的方法
Shell array
ZUCC_ Principles of compiling language and compilation_ Experiment 08 parsing LR parsing
orb slam build bug: undefined reference to symbol ‘_ ZN5boost6system15system_ categoryEv‘
ZUCC_ Principles of compiling language and compilation_ Experiment 03 getting started with compiler
日本大阪大学万伟伟研究员介绍基于WRS系统机器人的快速集成方法和应用
How to replace the web player easyplayerproactivex Key in OCX?
所说的Get post:请求的区别,你真的知道了吗??????
Qt源码分析--QObject(2)
Earthly container image construction tool -- the road to dream
Get screen width and height tool class
等保备案是什么意思?应该去哪里办理备案?
Shell basic operator -- arithmetic operator
Battle history between redis and me under billion level traffic
orb slam build bug: undefined reference to symbol ‘_ZN5boost6system15system_categoryEv‘
ZUCC_ Principles of compiling language and compilation_ Experiment 01 language analysis and introduction