I get this filter:
userInfo = $filter('filter')(userArray, {userId: userId});
and got the userInfo object. Is there anyway that I can find out which array index of userArray. Thanks
I get this filter:
userInfo = $filter('filter')(userArray, {userId: userId});
and got the userInfo object. Is there anyway that I can find out which array index of userArray. Thanks
Following the docs, you can see that you can use a function instead of the object {userId: userId}. https://docs.angularjs.org/api/ng/filter/filter#filter-arguments
Right now your code should be equivalent to the following:
userInfo = $filter('filter')(userArray, function(element, index) {
if (element.userId == userId) return true;
});
Note that the function added to the filter contains the index that you need.
You may change the function to make use of that index, but bear in mind that you must return true only for the elements that you want to pass the filter.