0

currently i am getting objects value in $scope.validuser but i want this into array form how do i store object value to array i jst want to store $scope.validuser into array i.e array[object]

  $scope.sportIds = [];
            angular.forEach($scope.users, function(value, key){
                $scope.sportIds[value.sport_id] = value.sport_id;
                if($scope.sportIds[value.sport_id] == 3){
                  $scope.validuser = value;
                  }
              });
2
  • Very unclear. Let's say your object is {id: 42, name:'Jimmy', age: 27}. What should the array contain? Commented May 3, 2016 at 11:00
  • As far as I could understand your question, you want $scope.validuser to be an array, including the value at each index - right? Commented May 3, 2016 at 11:01

1 Answer 1

1

This will give you an array containing only the valid users:

$scope.validuser = $scope.users.filter(function(user) {
  return user.sport_id === 3;
});
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.