查找Vue中下标的操作(some和findindex)
some的用法
list:[ {id:1,name:’奔驰’,citme:new Date()}, {id:2,name:’宝马’,citme:new Date()} ] - // this.list.some((item,i)=>{// if(item.id==id){// this.list.splice(i,1)// return true// }// })
其中some是比较list中每一项的id值,然后把这个id值给了item,item.id就代表了list中的每一项id值,如果返回true,就不再往后执行
var index= this.list.findIndex(item=>{ if(item.id==id){ return true }})
findIndex 同理也是遍历list中的id值,item.id就是list中的id值
补充知识:vue处理对象数组(下标和值)
我就废话不多说了,大家还是直接看代码吧~
Storelist(){ this.$api.question().then(res=>{ if (res.status==1){ let that = this let a = res.result.store // a是获取接口的对象数组 console.log(a) console.log(a.length) // 对象数组--数据的长度 var groupCount = Object.getOwnPropertyNames(a).length; console.log(groupCount) // 对象数组的下标 var keys1 = [] for (var p1 in a) {if (a.hasOwnProperty(p1)) keys1.push(p1); } console.log(keys1)//组合数据-拼接成数组 let qqq = [] for (let i=0;i<keys1.length;i++){console.log(keys1[i])console.log(a[keys1[i]])qqq.push({ pid:keys1[i], name:a[keys1[i]]}) } console.log(qqq) } }) },
以上这篇查找Vue中下标的操作(some和findindex)就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持好吧啦网。
相关文章:
1. Python3.8 + Tkinter: Button设置image属性不显示的问题及解决方法2. 气象 XML 数据源应用程序开发指南-简介3. EJB3.0部署消息驱动Bean抛javax.naming.NameNotFoundException异常4. 一文掌握ajax、fetch和axios的区别对比5. js获取今天、昨天、明天的日期函数代码6. .Net core Blazor+自定义日志提供器实现实时日志查看器的原理解析7. 前端设置cookie之vue-cookies使用及说明8. PHP对接阿里云虚拟号的实现(号码隐私保护)9. Python Django路径配置实现过程解析10. Java SQL注入案例教程及html基础入门
