有一个数字数组 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]);
}
}
最佳答案
循环a
并检查b
for (var i = 0; i < a.length; i++) {
if (b.indexOf(a[i]) === -1) c.push(a[i]);
}
关于javascript - JS - 数组,仅推送某些值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25795067/