title: Check if Express request data is array
body: <p>I've working on an Express 3.x API server (don't ask why I'm not upgrading to 4.x; I'm not in control of that), and I'm trying to implement support for batch requests for a particular endpoint. The endpoint currently supports regular requests (takes a JSON object), but I want it to also be able to take array of JSON objects, e.g.:</p>
  
  <pre><code>POST /api/posts
  Body:
  [
    { "title": "Hello World", "text": "blah blah" },
    { "title": "Hello World 2", "text": "blah blah blah" }
  ]
  </code></pre>
  
  <p>When I try to access the body of the request for a single request using <code>req.body</code>, I can retrieve the data just fine (it's just a regular JSON object). However, when I send an array, I find that the data gets parsed as an object of objects(?) instead of an array.</p>
  
  <pre><code>req.body = { "title": "Hello World", "text": "blah blah" };
  typeof req.body;
  // object
  req.body.toString();
  // [object Object]
  
  req.body = [
    { "title": "Hello World", "text": "blah blah" },
    { "title": "Hello World 2", "text": "blah blah blah" }
  ];
  typeof req.body;
  // object
  req.body.toString();
  // [object Object],[object Object]
  </code></pre>
  
  <p>I tried using a simple check like this:</p>
  
  <pre><code>if (req.body.toString() !== '[object Object]') {
  </code></pre>
  
  <p>But an array containing only one object breaks this. E.g.:</p>
  
  <pre><code>req.body = [{ "title": "Hello World", "text": "blah blah" }];
  typeof req.body;
  // object
  req.body.toString();
  // [object Object]
  </code></pre>
  
  <p>Given this, is there guaranteed way to check to see if my data is an array?</p>