查找Vue中下標(biāo)的操作(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,就不再往后執(zhí)行
var index= this.list.findIndex(item=>{ if(item.id==id){ return true }})
findIndex 同理也是遍歷list中的id值,item.id就是list中的id值
補(bǔ)充知識:vue處理對象數(shù)組(下標(biāo)和值)
我就廢話不多說了,大家還是直接看代碼吧~
Storelist(){ this.$api.question().then(res=>{ if (res.status==1){ let that = this let a = res.result.store // a是獲取接口的對象數(shù)組 console.log(a) console.log(a.length) // 對象數(shù)組--數(shù)據(jù)的長度 var groupCount = Object.getOwnPropertyNames(a).length; console.log(groupCount) // 對象數(shù)組的下標(biāo) var keys1 = [] for (var p1 in a) {if (a.hasOwnProperty(p1)) keys1.push(p1); } console.log(keys1)//組合數(shù)據(jù)-拼接成數(shù)組 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中下標(biāo)的操作(some和findindex)就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 基于javaweb+jsp實現(xiàn)企業(yè)車輛管理系統(tǒng)2. 怎樣才能用js生成xmldom對象,并且在firefox中也實現(xiàn)xml數(shù)據(jù)島?3. 利用ajax+php實現(xiàn)商品價格計算4. ASP.Net MVC利用NPOI導(dǎo)入導(dǎo)出Excel的示例代碼5. jstl 字符串處理函數(shù)6. JSP動態(tài)網(wǎng)頁開發(fā)原理詳解7. PHP中為什么使用file_get_contents("php://input")接收微信通知8. .Net core Blazor+自定義日志提供器實現(xiàn)實時日志查看器的原理解析9. IOS蘋果AppStore內(nèi)購付款的服務(wù)器端php驗證方法(使用thinkphp)10. XML CDATA是什么?
