js筛选数据?

let arr1 = [

{

"eHireJobID": "241206141",

"name": "测试导入190821"

},

{

"eHireJobID": "0",

"name": "../../../../../../etc/passwd"

},

{

"eHireJobID": "241189468",

"name": "bannedwirdtest"

},

{

"eHireJobID": "241192916",

"name": "181107新增职位2"

},

{

"eHireJobID": "241186470",

"name": "appp"

},

{

"eHireJobID": "241192918",

"name": "181107新增职位2"

},

{

"eHireJobID": "241186017",

"name": "test2"

},

{

"eHireJobID": "0",

"name": "reetretre"

},

{

"eHireJobID": "241186015",

"name": "tetete"

},

{

"eHireJobID": "241192917",

"name": "删除多余文件"

},

{

"eHireJobID": "241257974",

"name": "200518新增职位通天塔"

}

]

let arr2 = [

"测试导入190821",

"181107新增职位2"

]

数据如上,想要从arr2里面对应找出arr1里的eHireJobID,最后组成数组[241192918,241192916]这样,应该如何修改


回答:

let data = arr1.filter((x) => arr2.some((y) => y === x.name)).map(z => z.eHireJobID)

console.log(data)


回答:

function getTagetsByKeys(keyArr = [], sourceArr = [], key = 'name', targetKey) {

return keyArr.map(name => {

let item = sourceArr.find(r => r[key] === name)

if (item) {

return item[targetKey]

}

}).filter(r => !!r)

}


回答:

只提供思路。
可以将 arr 遍历成 let obj = { "name":["eHireJobID","eHireJobID2"] },通过遍历 arr2 去匹配 obj 的 key 去查找。


回答:

试试如下代码

js">new Set((arr1.filter(item => arr2.includes(item.name)).map(item=> item.eHireJobID)))

以上是 js筛选数据? 的全部内容, 来源链接: utcz.com/p/933413.html

回到顶部