猿问

关于依靠a数组筛选b数组内没有存在a数组元素

A数组--tableSelectParams:["id","device_code","value"]
B数组-- "tag_columns":[{

       "column_desc": "id",                    "column_name": "id",                    "isShow": true
                    },
                    {                    "column_name": "device_code",                    "column_desc": "设备编号",                    "isShow": true
                    },
                    {                    "column_name": "companyid",                    "column_desc": "公司ID",                    "isShow": true
                    },
                    {                    "column_name": "addtime",                    "column_desc": "添加时间",                    "isShow": true
                    },
                    {                    "column_name": "value",                    "column_desc": "值",                    "isShow": true
                    }
                ]

请问如何找出B数组中 column_name没有和A数组元素相同的B数组对象。
求帮忙看看。

慕码人2483693
浏览 328回答 2
2回答

Smart猫小萌

let columns = tag_columns.filter(cur => !tableSelectParams.includes(cur.column_name))

隔江千里

// 生成映射表,避免过多的内循环 var map = tableSelectParams.reduce((p, c) => [p[c] = false, p][1]) var result = tag_columns.filter(i => map[i.column_name])
随时随地看视频慕课网APP
我要回答