<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title></title> <link rel="stylesheet" href=""> </head> <body> <script> let arr = [ { name: "1", id: "1" }, { name: "2", id: "2" }, { name: "3", id: "3" }, { name: "4", id: "4" } ] let p =[1,3]; let a =[]; for (let i = 0;i<arr.length;i++) { let flag =false; for (let j = 0; j < p.length; j++) { if(p[j]==i){ flag =true; break; } if(j==p.length-1 && !flag){ a.push(i); } } } let postArr =[]; for (let i = 0; i < a.length; i++) { postArr.push(arr[a[i]]); } console.log(postArr); </script> </body> </html>
原文:https://www.cnblogs.com/yanchangcheng/p/9527166.html