js通过一个数组,删除数据中对应的id
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <script> var data1 = ['1', '3']; var data2 = [{ id: "1", name: "试试" }, { id: "2", name: "试试2" }, { id: "3", name: "试试3" }]; console.log(deleteShopFilter(data1, data2)); function deleteShopFilter(arr1, arr2) { return arr2.filter( (e) => arr1.filter((x) => e.id != x).length == arr1.length ); } </script> </body> </html>
打印的结果