title: Cannot access elements in object returned by Javascript Function in AngularJS
body: <p>Thanks to @asgoth, I am able to use AngularJS $http service to retrieve stock prices from Yahoo as described here:  <a href="https://stackoverflow.com/questions/13963192/cannot-read-response-from-angularjs-resource-jsonp-get-from-yahoo-finance">Cannot read response from AngularJS $resource JSONP get from Yahoo Finance</a></p>
  
  <p>In the "getHistoricalPrice" function, it puts the price inside an array, which is inside an object.  From inside that function, I am able to access the price and write it to console.</p>
  
  <p>The function returns the object to where it is called from.  From there, I can successfully write the entire object out to console.  However, I cannot access the elements of this object.  I tried many different ways, but still cannot access the data in the object.  You can see the code at <a href="http://jsfiddle.net/curt00/LTazR/2/" rel="nofollow noreferrer">http://jsfiddle.net/curt00/LTazR/2/</a> or below:</p>
  
  <pre><code>angular.module('app', ['ngResource']);
  
  function AppCtrl($scope, $http, $resource) {
  
  var historical_price = getHistoricalPrice("AAPL", 'start date is hard coded', 'end date is hard coded');
  console.log("after calling historical price: ", historical_price);  // historical_price is an object and all of the correct data is outputted to console here, but I cannot access its elements directly from Javascript.
  
  for(var key in historical_price) {
      console.log("key =",key);  // this outputs "key = list"
  }
  
  console.log("after calling getHistoricalPrice: ", historical_price.list[0][1]);  // Cannot access this as browser console gives error: TypeError: Cannot read property '1' of undefined
  console.log("after calling getHistoricalPrice: ", historical_price['list'][0][1]);  // Cannot access this as browser console gives error: TypeError: Cannot read property '1' of undefined
  console.log("after calling getHistoricalPrice: ", historical_price[0][1]);  // Cannot access this as browser console gives error: TypeError: Cannot read property '1' of undefined
  
  
  function getHistoricalPrice(symbol, start, end) {
  
      var query = 'select * from csv where url=\'http://ichart.yahoo.com/table.csv?s=' + symbol + '&amp;a=' + '11' + '&amp;b=' + '19' + '&amp;c=' + '2012' + '&amp;d=' + '11' + '&amp;e=' + '19' + '&amp;f=' + '2012' + '&amp;g=d&amp;ignore=.csv\'';
  
  
      var url = 'http://query.yahooapis.com/v1/public/yql?q=' + fixedEncodeURIComponent(query) + '&amp;format=json&amp;callback=JSON_CALLBACK';
  
      var histData = {};
  
      $http.jsonp(url, {timeout: 30000}).success(function(json) {
          var list = [];
  
  
          var result = json.query.results.row;
  
          result.shift(); // remove the header (columns) row
          angular.forEach(result, function(row) {
              list.push([(new Date(row.col0)).getTime()/1000, parseFloat(row.col4)]);
  
          });
          list.sort(function(val1, val2) {
              return val1[0] - val2[0];
          });
          histData.list = list;
          console.log('Loaded historical data',histData.list[0][1],', for ' + symbol);  // This works and gives the price
      });
  
      return histData;
  }
  
  var fixedEncodeURIComponent = function(str) {
      return encodeURIComponent(str).replace(/[!'()]/g, escape).replace(/\*/g, "%2A");
  };
  
  
  
  }
  </code></pre>
  
  <p>​<br>
  Any help or suggestions to solve this problem is greatly appreciate!</p>