如果不知道这是否最有效,但可能最短
A = [1, 2, 3, 4];B = [1, 3, 4, 7];diff = A.filter(function(x) { return B.indexOf(x) < 0 })console.log(diff);
更新到ES6:
A = [1, 2, 3, 4];B = [1, 3, 4, 7];diff = A.filter(x => !B.includes(x) );console.log(diff);
欢迎分享,转载请注明来源:内存溢出
如果不知道这是否最有效,但可能最短
A = [1, 2, 3, 4];B = [1, 3, 4, 7];diff = A.filter(function(x) { return B.indexOf(x) < 0 })console.log(diff);
更新到ES6:
A = [1, 2, 3, 4];B = [1, 3, 4, 7];diff = A.filter(x => !B.includes(x) );console.log(diff);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)