title: Why my function get 0 results?
body: <p>Hey what i have here is like 3 functions that works together. But the problem is the last one which is called doesnt iterate over thata becouse it sees is as an empty array. Funny thing is when i do <code>console.log()</code> whole object it has a data in that array, but when i log only that array element from that object it is empty. Why ?</p>
  
  <p>Here you is a codepen: <a href="http://codepen.io/anon/pen/NqoYjd?editors=101" rel="nofollow">http://codepen.io/anon/pen/NqoYjd?editors=101</a></p>
  
  <p>Here is how it looks like:</p>
  
  <pre><code>getPlacesInArea: function($scope, types, callback) {
      for (var key in types) {
          if (types.hasOwnProperty(key) &amp;&amp; types[key].checked) {
              this.getPlace($scope, key);
          }
      }
      callback($scope);
  },
  </code></pre>
  
  <p>So what happens here is just i load data from api to the scope vairable.</p>
  
  <pre><code>getAttractionsInArea: function($scope, typesValue) {
      placesService.getPlacesInArea($scope, typesValue, this.showAttractionMarkers);
  },
  showAttractionMarkers: function($scope) {
      placesService.showPlacesMarkers($scope.map, $scope.attractionsMarkers);
  }
  </code></pre>
  
  <p>Here where is the place were the <code>getPlacesInArea</code> is called.
  In the <code>getAttractionsInArea</code> i also pass as a callback <code>showAttractionMarkers</code> method.</p>
  
  <pre><code>showPlacesMarkers: function(map, markers) {
      if (typeof map != 'undefined') {
          for (var key in markers) {
              if (markers.hasOwnProperty(key)) {
                  mapService.setMapForMarkers(markers[key].items, map);
              }
          }
      } else {
          for (var type in markers) {
              if (markers.hasOwnProperty(type)) {
                  mapService.setMapForMarkers(markers[type].items, null);
              }
          }
      }
  },
  </code></pre>
  
  <p>Here we are in that function if i do <code>console.log(markers)</code> i see that markers[type].items has items. But if i do <code>console.log(markers[type].items)</code> the array is empty. Why is that? how can i fix it ?</p>
  
  <p>Here is <code>console.log(markers);</code></p>
  
  <pre><code>Object {food: Object, art_gallery: Object, museum: Object, night_club: Object}
  </code></pre>
  
  <p>And here is example of food object</p>
  
  <pre><code>food: Object
      checked: true
      icon: null
      items: Array[20]
          0: MarkerWithLabel
          1: MarkerWithLabel
          2: MarkerWithLabel
          3: MarkerWithLabel
          4: MarkerWithLabel
          5: MarkerWithLabel
          6: MarkerWithLabel
          7: MarkerWithLabel
          8: MarkerWithLabel
          9: MarkerWithLabel
          10: MarkerWithLabel
          11: MarkerWithLabel
          12: MarkerWithLabel
          13: MarkerWithLabel
          14: MarkerWithLabel
          15: MarkerWithLabel
          16: MarkerWithLabel
          17: MarkerWithLabel
          18: MarkerWithLabel
          19: MarkerWithLabel
          length: 20
      __proto__: Array[0]
  __proto__: Object
  </code></pre>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var $scope,
    objectByString = function(o, s) {
      s = s.replace(/\[(\w+)\]/g, '.$1');
      s = s.replace(/^\./, '');
      var a = s.split('.');
      for (var i = 0, n = a.length; i &lt; n; ++i) {
        var k = a[i];
        if (k in o) {
          o = o[k];
        } else {
          return;
        }
      }
      return o;
    },
    getMarkersPath = function(amountPath) {
      var paths = amountPath.split('.');
  
      return paths[paths.length - 1] + 'Markers';
    },
    getAttractionsInArea = function($scope, typesValue) {
      getPlacesInArea($scope, typesValue, 'filters.location.attractions', 'fa-star', showAttractionMarkers);
    },
    showAttractionMarkers = function($scope) {
      var checked = $scope.searchData.filters.location.attractions.checked;
  
      if (checkPropertyExistence($scope, ['attractionsMarkers'])) {
        showPlacesMarkers($scope.map, $scope.attractionsMarkers, checked);
      }
    },
  
    clearPlacesMarkers = function($scope, markersPath) {
      if (checkPropertyExistence($scope, [markersPath])) {
        var types = $scope[markersPath];
        for (var type in types) {
          if (types.hasOwnProperty(type)) {
            setMapForMarkers(types[type].items, null);
          }
        }
      }
    },
    showPlacesMarkers = function(map, markers, checked) {
      if (typeof map != 'undefined' &amp;&amp; checked) {
        for (var key in markers) {
          if (markers.hasOwnProperty(key) &amp;&amp; markers[key].checked) {
            setMapForMarkers(markers[key].items, map);
          }
        }
      } else {
        for (var type in markers) {
          if (markers.hasOwnProperty(type) &amp;&amp; markers[type].checked) {
            setMapForMarkers(markers[type].items, null);
          }
        }
      }
    },
    getPlacesInArea = function($scope, types, propertyPath, icon, callback) {
      var markersPath = getMarkersPath(propertyPath);
      this.clearPlacesMarkers($scope, markersPath);
  
      addToProperty($scope.searchData, propertyPath + '.amount', 0);
      $scope[markersPath] = types;
      types = $scope[markersPath];
  
      if (typeof $scope.map != 'undefined') {
        for (var key in types) {
          if (types.hasOwnProperty(key) &amp;&amp; types[key].checked) {
            this.getPlace($scope, key, propertyPath, icon);
          }
        }
        callback($scope);
      }
    },
    getPlace = function($scope, key, propertyPath, icon) {
      var service = new google.maps.places.PlacesService($scope.map),
        request = {
          location: new google.maps.LatLng($scope.searchData.location.lat, $scope.searchData.location.lon),
          radius: 700,
          types: [key]
        },
        markersPath = getMarkersPath(propertyPath);
  
      service.nearbySearch(request, function(results, status) {
        if (status == google.maps.places.PlacesServiceStatus.OK) {
          var markers = [],
            amount = objectByString($scope.searchData, propertyPath + '.amount');
  
          for (var i = 0; i &lt; results.length; i++) {
            var place = results[i];
  
            var typeIcon = null;
            if (checkPropertyExistence($scope, [markersPath, key, 'icon'])) {
              typeIcon = objectByString($scope, markersPath + '.' + key + '.icon');
            }
  
            var markerIcon = (typeIcon !== null ? typeIcon : (icon !== null ? icon : place.icon)),
              marker = addMarker(place.geometry.location, null, markerIcon);
  
            addInfoBubble(marker, place.name, place.vicinity.substr(0, 70), markerIcon, $scope.map, key.replace(/_/g, ' '));
            markers.push(marker);
  
            if (checkPropertyExistence($scope, [markersPath, key, 'items'])) {
              $scope[markersPath][key]['items'] = markers;
            }
          }
  
          addToProperty($scope.searchData, propertyPath + '.amount', amount + markers.length);
        }
      })
    },
    addToProperty = function($searchData, $keyString, $value) {
      var keys = $keyString.split(".");
      lastKeyIndex = keys.length - 1;
      for (var i = 0; i &lt; lastKeyIndex; ++i) {
        key = keys[i];
        if (!(key in $searchData))
          $searchData[key] = {};
        $searchData = $searchData[key];
      }
      $searchData[keys[lastKeyIndex]] = $value;
    },
    checkPropertyExistence = function(obj, paths) {
      for (var i = 0; i &lt; paths.length; i++) {
        if (!obj || !obj.hasOwnProperty(paths[i])) {
          return false;
        }
        obj = obj[paths[i]];
      }
      return true;
    },
    addMarker = function(point, map, icon, color) {
      if (typeof color == 'undefined') {
        color = "#000000";
      }
      return new MarkerWithLabel({
        position: point,
        map: map,
        icon: ' ',
        labelContent: '&lt;i class="fa ' + icon + ' fa-2x" style="color:' + color + ';"&gt;&lt;/i&gt;',
        labelAnchor: point
      });
    },
    addInfoBubble = function(marker, title, content, icon, map, additionalInfo) {
      if (typeof icon == 'undefined') {
        icon = "fa-map-marker";
      }
  
      if (typeof additionalInfo == 'undefined') {
        additionalInfo = "";
      }
  
      var bounds = map.getBounds(),
        myOptions = {
          content: "&lt;div class='info'&gt;" +
            "&lt;div class='infoBubble'&gt;" +
            "&lt;h4&gt;&lt;i class='fa " + icon + "'&gt;&lt;/i&gt; " + title + " &lt;small&gt;" + additionalInfo + "&lt;/small&gt;&lt;/h4&gt;" +
            "&lt;p&gt;" + content + "&lt;/p&gt;" +
            "&lt;/div&gt;" +
            "&lt;/div&gt;",
          disableAutoPan: true,
          position: new google.maps.LatLng(bounds.getNorthEast().lat(), bounds.getSouthWest().lng()),
          isHidden: false,
          closeBoxURL: ""
        };
  
      var infobox = new InfoBox(myOptions);
  
      google.maps.event.addListener(marker, 'mouseover', function() {
        infobox.open(map);
      });
      google.maps.event.addListener(marker, 'mouseout', function() {
        infobox.close();
      });
  
      return infobox;
  
    },
    setMapForMarkers = function(markers, map) {
      var self = this;
      for (var i = 0; i &lt; markers.length; i++) {
        try {
          markers[i].setMap(map);
        } catch (e) {
  
        }
      }
    };
  
  function initialize() {
    $scope = {
      searchData: {
        location: {
          lat: 40.722840,
          lon: -73.999585
        }
      },
      filters: {
        location: {
          attractions: {
            checked: true
          }
        }
      }
    };
    var mapProp = {
      center: new google.maps.LatLng(40.722840, -73.999585),
      zoom: 15,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    $scope.map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
    $scope.getAttractionsInArea = function() {
      var value = {
        food: {
          checked: true,
          icon: null,
          items: []
        },
        art_gallery: {
          checked: true,
          icon: null,
          items: []
        },
        museum: {
          checked: true,
          icon: null,
          items: []
        },
        night_club: {
          checked: true,
          icon: null,
          items: []
        }
      };
  
      getAttractionsInArea($scope, value);
    };
    $scope.showAttractionMarkers = function() {
      showAttractionMarkers($scope);
    };
    $scope.getAttractionsInArea();
  }
  
  function show(element) {
    element.checked ? $scope.filters.location.attractions.checked = true : $scope.filters.location.attractions.checked = false;
    $scope.showAttractionMarkers();
  }
  
  initialize();</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://maps.googleapis.com/maps/api/js?v=3.exp&amp;libraries=places"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/src/infobox.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="http://google-maps-utility-library-v3.googlecode.com/svn/trunk/markerwithlabel/src/markerwithlabel.js"&gt;&lt;/script&gt;
  &lt;label&gt;
    &lt;input type="checkbox" value="check" id="xxx" onchange="show(this)" /&gt;Show markers
  &lt;/label&gt;
  &lt;div id="googleMap" style="width:500px;height:380px;"&gt;&lt;/div&gt;</code></pre>
  </div>
  </div>
  </p>