cartodb-4.42/lib/assets/javascripts/deep-insights/util/get-object-value.js

16 lines
564 B
JavaScript
Raw Normal View History

2024-04-06 13:25:13 +08:00
/**
* Gets the value at path of object. If the resolved value is undefined, the defaultValue is returned in its place.
* @param {Object} object The object to query.
* @param {String} path The path of the property to get.
* @param {Any} defaultValue The value returned for undefined resolved values.
* @return {Any} Returns the resolved value.
*/
module.exports = function (object, path, defaultValue) {
var keys = path.split('.');
var value = keys.reduce(function (a, b) {
return (a || {})[b];
}, object);
return value || defaultValue;
};