title: Express Response: Sending an Array as JSON
body: <p>I'm having an issue trying to get data from my backend express api. I'm using mongodb and mongoose too. Here's my code:
  Code:</p>
  
  <pre><code>const show = (req, res) =&gt; {
    const product = {}
    product.array = new Array()
    console.log(req.cart.product[1])
    for (let i = 0; i &lt; req.cart.product.length; i++) {
    Product.find({_id: ObjectId(req.cart.product[i])},function(err,products){
           if (err) {
              res.sendStatus(500)
          } else {
                product.array.push(products)
                console.log(product.array)
              }
            })
          }
          req.cart.product = product.array
            res.json({
              cart: req.cart.toJSON({ virtuals: true, user: req.user })
            })
      }
  </code></pre>
  
  <p>Console.logs:</p>
  
  <pre><code>[ [ { _id: 5952b57ea52d092b8d34c6b0,
        name: 'test00000',
        price: 0,
        description: 'test',
        __v: 0 } ] ]
  [ [ { _id: 5952b57ea52d092b8d34c6b0,
        name: 'test00000',
        price: 0,
        description: 'test',
        __v: 0 } ],
    [ { _id: 5952b57ea52d092b8d34c6b0,
        name: 'test00000',
        price: 0,
        description: 'test',
        __v: 0 } ] ]
  </code></pre>
  
  <p>URL Response:</p>
  
  <pre><code>{
      "cart": {
          "_id": "5953b153d2108941d15a7fe9",
          "updatedAt": "2017-06-28T13:38:27.406Z",
          "createdAt": "2017-06-28T13:38:27.406Z",
          "owner": "595153ad6f18427ef38c416b",
          "__v": 0,
          "product": [],
          "id": "5953b153d2108941d15a7fe9",
          "editable": false
      }
  }
  </code></pre>
  
  <p>Everything in the console logs is what I want to return in the products array for my response but it won't populate the array when I push it. Any thoughts?</p>