Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi -

Have what seems to be simple issue. I have a ui-select drop down list. On that is a onChange event method. What I want to happen is when an item is selected and changed I have 3 arrays. One I'm looping through that array to make sure I have types and of those whose type property checked is true I am looping through another array to compare. If I have a match I push that object into the 3rd array. After the loops finish I am trying to remove the first object in the array.

Suggestions -

Thanks
Here is my code
JavaScript
vm.backtypes =[];
vm.types = [];
vm.changeEvent = function(ctrl){
    if(vm.backtypes.length > 0){
        angular.forEach(vm.backtypes, function (x) {
            if(x.checked){;
                angular.forEach(ctrl.backOptionSelected, function(s){
                    if(x.id == s)
                    {
                        vm.types.push(x);
                        //vm.types.shift();

                    }
                });//end 2nd foreach
            }//end if
        });//end first foreach
    }//end if
    vm.types.shift();
    console.log(vm.types);
}//end changeEvent



What I have tried:

I have tried .shift() and I have tried .splice().
Posted
Comments
Karthik_Mahalingam 7-Mar-17 16:35pm    
are you getting values in console.log(vm.types); ?
Troy Bryant 7-Mar-17 17:53pm    
yes at the end the array is empty if I .shift() there. If I do it right after I've pushed x into the array I'm still getting both values.
Karthik_Mahalingam 7-Mar-17 18:01pm    
shift() will remove the top most item in an array.
Troy Bryant 7-Mar-17 18:02pm    
Thats what I want but not behaving that way so thought was something I wasnt doing or had it in the wrong spot
Karthik_Mahalingam 7-Mar-17 18:07pm    
what is the value here
console.log(JSON.stringify(vm.types));

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900