es6 js 匹配两个数组对象的方法
短信预约 -IT技能 免费直播动态提醒
判断两个数组用的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: "公司领导",
mobile: "",
realname: "贺金生",
com_name: "任公司",
label: "贺xx",
value: 1004
},
{
user_type: 0,
user_id: 1005,
department_id: 1,
department_name: "公司领导",
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: "公司领导",
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
到此这篇关于es6 js 匹配两个数组对象的方法的文章就介绍到这了,更多相关es6 js 匹配数组对象内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341