假如有两个数组,怎样把两个数组的差集push进$scope.dataIndex这个数组啊
如果不引入其他第三方库的情况下,如何用js 得到差集呢
let tempData = [5, 6, 8];
let tempArr = [5, 6, 7, 8];
$scope.dataIndex = [];
angular.forEach(tempData, function(item, index) {
//if (tempArr.indexOf(item.Id) !== -1) {
// $scope.dataIndex.push(item.Id);
// console.log(item);
// }
});
这是我项目里自己写的 因为有特殊需求要支持对象的差集 那段没贴出来
如果支持es6可以用这段
underscore库有_.difference