You can check it with typeof:
if(typeof aggs.times.date_histogram['interval'] !== 'undefined') { // ... exists ... }
Another method is using the in keyword (this one is prettier and more obvious imho)
if('interval' in aggs.times.date_histogram) { // ... exists ... }
The above is assuming aggs.times.date_histogram exists (and doesn't need an existence check)
Update: For checking the existence of everything leading to the value you need, you can use this:
function getProp(_path, _parent) { _path.split('.').forEach(function(_x) { _parent = (!_parent || typeof _parent !== 'object' || !(_x in _parent)) ? undefined : _parent[_x]; }); return _parent; }
You can call it like:
getProp('aggs.times.date_histogram.interval', parent_of_aggs);
Will return the value of interval if it is defined, else it will return undefined