我有两个数组playerMoves
和movesList
。像这样。
var playerMoves= [4, 6];
var movesList= [[0,1,2],[0,3,6]];
我需要过滤movesList
数组,以使playerMoves
数组的值不应出现在movesList
的每个数组中。
console.log(move);
// should return [0,1,2]
我的尝试
var playerMoves= [4, 6];
var movesList= [[0,1,2],[0,3,6]];
var move = movesList.filter(v => v.filter(c => {
return playerMoves.indexOf(c) === -1;
}));
console.log(move);
答案 0 :(得分:3)
您可以使用Array#filter
,Array#every
和Array#includes
的混合。
let playerMoves = [4, 6];
let movesList = [
[0, 1, 2],
[0, 3, 6],
[5, 7, 9],
];
let res = movesList.filter(v => v.every(c => !playerMoves.includes(c)));
console.log(JSON.stringify(res));