0

i have tree of checkboxes . Departments and under each department there are some checkboxes for employees. when user check on department all employees are selected under this department. I add the unique departments keys to an array. My problem is how to remove the unchecked department key from the array.

$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);
            }

       console.log($scope.depts);
    }
3
  • do you want to remove that entire department from the array or just only the key of that department? Commented Sep 29, 2018 at 12:25
  • 1
    if you just want to remove a key from the object, you can do this delete Object[key]; in your for loop while checking if they have unchecked department or not. Commented Sep 29, 2018 at 12:36
  • i just want to remove the key, kindly can you show me a full example, thanks lot Commented Sep 29, 2018 at 12:43

1 Answer 1

2

If you just want to remove the key of object then you can do it this way:

m.forEach(function (dept) {

if(condition) // this is where you check if this department is checked or unchecked
    delete dept[Dep_key];
});

Of course this only a vague example, I will need to know your actual object definition to give you a proper answer.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.