У меня есть следующий объект
0: {Dep_key: 1, sex: 2, dep: "HR department", Staff_name: "Hassan",
Staff_Key: 782, …}
1: {Dep_key: 1, sex: 2, dep: "sales department", Staff_name: "Ahmed",
Staff_Key: 813, …}
2: {Dep_key: 1, sex: 2, dep: "Marketing", Staff_name: "Hossam",
Staff_Key: 817, …}
, и я хочу вставить уникальные значения Dep_key
(s) в массив.Что я сделал
$scope.leftdept = function (m) {
console.log(m);
for (i = 0; i < m.length; i++) {
if ($scope.depts.indexOf(m[i].Dep_key) === -1) {
$scope.depts.push(m[i].Dep_key);
}
else {
var index = $scope.depts.indexOf(m);
$scope.depts.splice(index, 1);
}
}
console.log($scope.depts);
}
, но мой код вставляет не все Dep_key
.Любая помощь, пожалуйста?
Спасибо