Question: Probably an easy question, but I am making a call to an API that returns a full list of products in JSON. The products are listed under 4 categories in the JSON - 'connectivity','cables','routers' and 'servers'. Using the getProducts() function below, I assign the list of 'connectivity' products to a variable called $scope.connectivitylistOfProducts - and this is what I display to the user in the UI as a default.

```
productsServices.getProducts()
        .then(function (allProducts) {
            $scope.listOfProducts = allProducts.data.category[0];
    $scope.connectivitylistOfProducts = allProducts.data.category[0].connectivity;
        })
        .finally(function () {
});

```

In the UI, I have a select box that's contains a list of the categories where the user can change to view the products under the category they choose. changeProduct() is what is called to change the category

```
$scope.changeProduct = function () {
        // change the product
};

```

I am already loading the full list of categories and products into $scope.listOfProducts and I dont want to make another API call by calling getProducts again. I'm not sure how to set up another variable (for example $scope.routerslistOfProducts) and assing the correct products to it. Could anyone tell me the best way to handle this? Many thanks

Answer: 
Could you try to access lists by array notation:

you have:

```
$scope.listOfProducts = allProducts.data.category[0];

```

you could create a category variable:

```
$scope.category = 'connectivity';

```

and to access using, for example:

```
<div ng-repeat="product in listOfProducts[category]">

```
If your payload has all the arrays then on API call back assign to scope variable say $scope.mylist, now you bind $scope.mylist.categories to drop down and on drop down change send category Id to change function () and filter using for loop and equal operator , while running through loop I.e filtering , which ever product matches category push to a variable say $scope.filteredproducts ....and here you got your filtered products.

This is simple way to understand , there are better ways to maintain filtered arrays too.