当前位置:网站首页>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
}
]
边栏推荐
- JUC personal simple notes
- Numpy 中的方法汇总
- Redis的Cluster集群数据倾斜
- 饼状统计图,带有标注线,都可以自行设定其多种参数选项
- Application of tidb in Netease games
- 图片工具
- Tencent conference API - get rest API & webhook application docking information
- 教程篇(5.0) 08. Fortinet安全架构集成与FortiXDR * FortiEDR * Fortinet 网络安全专家 NSE 5
- 利用ngrok做内网穿透
- 5 minutes, excellent customer service chat handling skills
猜你喜欢

What is the future development trend of Business Intelligence BI

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

5 minutes, excellent customer service chat handling skills

ZUCC_ Principles of compiling language and compilation_ Experiment 08 parsing LR parsing

K8S部署高可用postgresql集群 —— 筑梦之路

How to improve the customer retention rate in the operation of independent stations? Customer segmentation is very important!

MATLAB Camera Calibrator相机标定

WebRTC系列-网络传输之5选择最优connection切换

uniapp 热更新后台管理

Pymysql inserts data into MySQL and reports an error for no reason
随机推荐
liunx服务器 telnet 带用户名 端口登陆方法
【力扣10天SQL入门】Day2
Lombok use
win11在cmder中使用vim查看内容的时候空白
项目部署相关
liunx 更改 vsftpd 的端口号
One development skill a day: how to establish P2P communication based on webrtc?
Variable declaration and some special variables in shell
PHP代码加密+扩展解密实战
2021-05-20computed和watch应用与区别
OpenCV to realize the basic transformation of image
RuntimeError: Missing dependencies:XXX
Common date formatter and QT method for obtaining current time
Redis cluster data skew
[untitled]
Cloudbase database migration scheme
解析互联网广告术语 CPM、CPC、CPA、CPS、CPL、CPR 是什么意思
xargs使用技巧 —— 筑梦之路
定时备份数据库脚本
Application of tidb in Netease games