JS请问怎么筛选这个数据?

请问怎么筛选这个数据? 比如arr数组中已经有10001,  就把data对象中的id为 10001筛选掉, 不要它,

http://img.mukewang.com/592920f300011a7604760403.jpg

var arr = ["10001","10003"];

var data =[

{

    id:"10001",

    name:"one"

},

{

    id:"10002",

    name:"two"

},

{

    id:"10003",

    name:"thri"

},

{

    id:"10004",

    name:"four"

}

];


SuperManSuperWorld
浏览 1994回答 3
3回答

hahhhha

试一下下面的逻辑。var arr = ["10001","10003"]; var data =[ { id:"10001", name:"one" }, { id:"10002", name:"two" }, { id:"10003", name:"thri" }, { id:"10004", name:"four" } ]; var newData = data.filter((j)=>{ var flag = true; for(k of arr){ if(k == j.id){ flag = false; break; } } return flag; }); console.log(newData);

慕的地8582982

XGETDKZXCIQHOSDUCOPSYPJHZAUOKNHPDBCJIISWQSIFMFAUKWJWJWEIGTKXUILXXFSHKCPQAOLMUVSNDPEKRXPBMXAHTLPAMKEAPAUSKVHDGARXORIGOJGYNRSNABSPQHSCAATHVSWNKEMVZNJXRLWDYVZWLJQYWRSTXOSMHBZAFFKYSGEITHJQHBWFDVZNCAFLDXDGZYCQTHUPJTDESGKBYFTHVZWBFZTAOVGGQUHVJJEKSNFTNRVSQKBARFGLBNFTLBQLITYDKZWQRCZYFVQUYQULEVIQGEKIGBYGLHKEKYCGXALCUZQOSUBLPQUHRRFVJAULCANXEICKFADBFIFZHCQKJZZEHVGDJNWRYFBPJJGSJJVSTFTATPQHLNDHLPMDNMZBFLDDJHKISMKAKJHYWWVANMTPGCQJWLWABSSALQRBFZTUXHYJLZUOYPHCCQURLVYCTTEELSUDHFDDTXUCFWWTXRVIDUEAPCPZWQYLCKUEFJNKULVSALUEUFZDKUKIGWGZEYMZZZXBEHHINTJULBQHSDEIQHBHODPQGODRLCPTPTCOZWCWDLFNTCPGWCRAXDCMMHZSYEVLQTOUNAVVIFEJCXKFENDJTHKKZIFCZJMFRKRQRNAAGUQCTWZUDMOXPMENQLWQYLIZKFLEGQSTSNMGPIXPFBEXOEXTJFNEDFZSRRJGMQVNVPIHROREYVRUDZOEWPMHPVXUZWTQRTAXJBSRCLTCRCQPOIOIRMFYYQZBFKMYAMYXIQYTFMEGTAGHYDZEIHPIHFRSPMEKLXPHRBEQVUQPJKNCOVLVYXYZZDFQLGPYKJAJHODIKTSLPBSABSEHNCKXSEQXWHQLVHPXCUCQSFAFKBGWHDLVORELOYQE
打开App,查看更多内容
随时随地看视频慕课网APP