有数组A。必须过滤掉存储在数组B中的某些值。结果应存储在数组C中。
JS
var a = [ 1,2,3,4,5,6];
var b = [ 2,4,6];
var c = []; // shall contain all values of a except the ones from b
这是我的方法:
for (var i = 0; i < a.length; i++){
if(b.indexOf(a[i]) === -1){
c.push(a[i]);
}
}
答案 0 :(得分:1)
循环a
并查看b
for (var i = 0; i < a.length; i++) {
if (b.indexOf(a[i]) === -1) c.push(a[i]);
}