Given a property accessor in dot notation eg. google.maps.places
, I need to evaluate the statement to get the property value.
var str = 'google.maps.places';
var statement = 'window["' + str.split('.').join('"]["') + '"]';
eval(statement);
Ofcourse, it works but I've never used eval
in production and would never want to, so just wondering if there's a better way? Also because this is a quick example but the function could accept accessors of any levels, just google
or google.maps
or even google.maps.places.autocomplete
.