es6?js?匹配兩個(gè)數(shù)組對(duì)象的方法
判斷兩個(gè)數(shù)組用的value是否相等
this.list = [ { user_type: 0, user_id: 1003, department_id: 1, department_name: "公司xx", mobile: "", realname: "廖xx", com_name: "任公司", label: "廖建平", value: 1003 }, { user_type: 0, user_id: 1004, department_id: 1, department_name: "公司領(lǐng)導(dǎo)", mobile: "", realname: "賀金生", com_name: "任公司", label: "賀xx", value: 1004 }, { user_type: 0, user_id: 1005, department_id: 1, department_name: "公司領(lǐng)導(dǎo)", mobile: "", realname: "李歡", com_name: "任公司", label: "李xx", value: 1005 } ] this.selectData = [ { user_type: 0, user_id: 1003, department_id: 1, department_name: "公司xx", mobile: "", realname: "廖xx", com_name: "任公司", label: "廖建平", value: 1003 }, { user_type: 0, user_id: 1004, department_id: 1, department_name: "公司領(lǐng)導(dǎo)", mobile: "", realname: "賀金生", com_name: "任公司", label: "賀xx", value: 1004 }, ]
方法一
let result = [] for (let i = 0; i < this.selectData.length; i++) { let obj = this.selectData[i] for (let j = 0; j < this.list.length; j++) { let aj = this.list[j] if (obj.value === aj.value) { result.push(aj) break } } } console.log("result", result)
方法二
let arr3 = this.selectData.filter(obj => this.list.some(obj1 => obj.value == obj1.value) ) console.info("arr3", arr3) this.result = arr3
方法三
let arr4 = [] let arr5 this.list.filter(obj => arr4.push(obj.value)) arr5 = this.selectData.filter(obj => arr4.indexOf(obj.value) !== -1) this.result = arr5
到此這篇關(guān)于es6 js 匹配兩個(gè)數(shù)組對(duì)象的方法的文章就介紹到這了,更多相關(guān)es6 js 匹配數(shù)組對(duì)象內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JS常見疑難點(diǎn)分析之match,charAt,charCodeAt,map,search用法分析
這篇文章主要介紹了JS常見疑難點(diǎn)分析之match,charAt,charCodeAt,map,search用法,結(jié)合實(shí)例形式較為詳細(xì)的分析了match,charAt,charCodeAt,map,search的功能,使用方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下2016-12-12淺析基于WEB前端頁(yè)面的頁(yè)面內(nèi)容搜索的實(shí)現(xiàn)思路
本文主要是想實(shí)現(xiàn)瀏覽器的CTRL+F功能,提供個(gè)思路和代碼,需要的朋友可以參考下2014-06-06JavaScript中改變this指向的三種方式總結(jié)
this?指向的值是可以通過手動(dòng)方式去改變的,比如call、bind、apply方法,本文主要為大家介紹了這三種方式的具體實(shí)現(xiàn)步驟,需要的可以參考下2023-12-12