I am working on displaying a mysql data table and creating a function which displays my data. When I run this function I receive the following error.

```
     for (var i = 0; i < res.length; i++) {
                              ^

TypeError: Cannot read property 'length' of undefined

```

---

```
function viewProducts(){
    var query = 'SELECT id, product_name, department, price, stock_quantity  FROM products Where stock_quantity > 0';

    connection.query(query, function(err, res){
        console.log('Items for Sale');
        console.log('Id \t Name \t Department \t Price \t Quantity\n');

            for (var i = 0; i < res.length; i++) {
                console.log(
                    res[i].id + '\t' + res[i].product_name + '\t' + res[i].department + '\t' + 
                    res[i].price + '\t' + res[i].quantity + '\n');
            };
         runSearch();
    });

}

```