title: how to extract specific data field from Javascript using jquery?
body: <p>I am not sure whether this question is already asked and I am new to jquery and javascript. But, I couldnt find any answer relevant to my question. I am trying to create an <a href="https://apify.com" rel="nofollow noreferrer">apify</a> crawler. I need to extract specific data from following javascript</p>
  
  <pre><code>&lt;script type="application/json" class="js-react-on-rails-component"&gt;
  {
      "assetHost": null,
      "version": "0.0.4-855-gda76bc6\n",
      "availableLocales": [
        "de",
        "en"
      ],
      .........
      "stats": {
          "visitors": [
            {
              "domestic": 600,
              "note": "incl. 250 conference participants",
              "year": 2017,
              "total": 600,
              "structure": null,
              "latest": true
            }
          ],
          "venue": [
            {
              "total": 376,
              "domestic": 376,
              "latest": true,
              "year": 2017
            }
          ],
          "exhibitors": [
            {
              "total_indirect": 0,
              "total": 46,
              "domestic": 46,
              "latest": true,
              "year": 2017
            }
          ]
        },
  
        ..........
        &lt;/script&gt;
  </code></pre>
  
  <p>I need to get the fields: <code>total</code> and <code>domestic</code> from <code>exhibitors</code> using jquery. I tried this query <code>(JSON.parse($('.js-react-on-rails-component').text())).exhibitors.total.text().trim()</code> But it didnt return anything. So, I tried to create a variable and called it on the result as follows:</p>
  
  <pre><code>function pageFunction(context) {
      var $ = context.jQuery;
      var exhibitor = JSON.parse($('.js-react-on-rails-component').text());
      var total = exhibitor.exhibitors.total;
      var domestic = exhibitor.exhibitors.domestic;
  
      if (context.request.label === "START") {
      .....
      } else { 
      var result = {
              total: total,
              domestic: domestic
          };
      return result;  
      }
  }
  </code></pre>
  
  <p>But, this code also doesnt return any result.</p>