Get the App
SLTechnology News&Howtos  ›  Development  › 

How do es6 and js match two array objects

Shulou Source: shulou.com Published: 2022-06-01 03:03:39 11月16日 Update

This article mainly introduces "how es6 and js match two array objects". In daily operation, I believe many people have doubts about how es6 and js match two array objects. Xiaobian consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the questions of "how es6 and js match two array objects". Next, please follow the editor to study!

Determine whether the value used by two arrays is equal

This.list = [{user_type: 0, user_id: 1003, department_id: 1, department_name: "Company xx", mobile: "", realname: "Liao xx", com_name: "Ren Company", label: "Liao Jianping" Value: 1003}, {user_type: 0, user_id: 1004, department_id: 1, department_name: "Company leadership", mobile: "", realname: "he Jinsheng", com_name: "Ren Company" Label: "he xx", value: 1004}, {user_type: 0, user_id: 1005, department_id: 1, department_name: "Company leaders", mobile: "", realname: "Li Huan" Com_name: "Ren Company", label: "Li xx", value: 1005}] this.selectData = [{user_type: 0, user_id: 1003, department_id: 1, department_name: "Company xx" Mobile: ", realname:" Liao xx ", com_name:" Ren Company ", label:" Liao Jianping ", value: 1003}, {user_type: 0, user_id: 1004, department_id: 1 Department_name: "Company leaders", mobile: ", realname:" he Jinsheng ", com_name:" Ren Company ", label:" he xx ", value: 1004},]

Method one

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

Method three

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

At this point, the study on "how es6 and js match two array objects" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Companies two arrays objects methods learning more he Jin Jianping help practical next articles theories knowledge articles websites materials follow questions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Apple Docker MariaDB Shulou Technology