title: Replace empty result coming from JSON with value
body: <p>I am using the following script in Google Sheets to fetch a JSON object from Yahoo!Finance for certain companies:</p>
  <pre><code>function yahooFinance(symbol) {
    const url = 'https://query2.finance.yahoo.com/v10/finance/quoteSummary/' + encodeURI(symbol)
      + '?modules=price,assetProfile,summaryDetail,incomeStatementHistory,'
      + 'balanceSheetHistory,defaultKeyStatistics,financialData,calendarEvents,'
      + 'recommendationTrend,upgradeDowngradeHistory,majorHoldersBreakdown'
      ;
    const response = UrlFetchApp.fetch(url, { muteHttpExceptions: true });
    const responseCode = response.getResponseCode();
    if (responseCode === 200) {
      const quote = JSON.parse(response.getContentText());
      return [[
        quote.quoteSummary.result[0].summaryDetail.dividendYield.fmt,
        quote.quoteSummary.result[0].summaryDetail.payoutRatio.fmt,
        quote.quoteSummary.result[0].summaryDetail.marketCap.fmt
      ]];
    }
    else {
      return &quot;-&quot;;
    }
  }
  </code></pre>
  <p>Regularly, however, for one or more keys, the value will be emptyy. In such a case, the JSON returns <code> </code> (an empty string). Whenever there is an empty string however, I would like to return a <code>-</code> back to the sheet to indicate that the query went fine, however no value was returned.</p>
  <p>So I tried updating as follows (see the <code>if</code> statement):</p>
  <pre><code>function yahooFinance(symbol) {
    const url = 'https://query2.finance.yahoo.com/v10/finance/quoteSummary/' + encodeURI(symbol)
      + '?modules=price,assetProfile,summaryDetail,incomeStatementHistory,'
      + 'balanceSheetHistory,defaultKeyStatistics,financialData,calendarEvents,'
      + 'recommendationTrend,upgradeDowngradeHistory,majorHoldersBreakdown'
      ;
    const response = UrlFetchApp.fetch(url, { muteHttpExceptions: true });
    const responseCode = response.getResponseCode();
    if (responseCode === 200) {
      const quote = JSON.parse(response.getContentText());
      return [[
        (if (quote.quoteSummary.result[0].summaryDetail.dividendYield.fmtr) quote.quoteSummary.result[0].summaryDetail.dividendYield.fmt),
        quote.quoteSummary.result[0].summaryDetail.payoutRatio.fmt,
        quote.quoteSummary.result[0].summaryDetail.marketCap.fmt
      ]];
    }
    else {
      return &quot;-&quot;;
    }
  }
  </code></pre>
  <p>Apparently, I cannot put an if-statement inside an array. How can I check each of the 3 values that I'm returning (<code>dividendYield</code>, <code>payoutRatio</code>, <code>marketCap</code>) if they are empty and if so, return <code>-</code>?</p>