diff --git a/objects.js b/objects.js index 997e716..8e52d22 100644 --- a/objects.js +++ b/objects.js @@ -234,4 +234,15 @@ var has = exports.has = function (obj, match) { //if match is a function, apply it to the corrisponding obj[key] } return true +} + +var setPath = exports.setPath = function (object, path, value) { + + for (var i in path) { + var key = path[i] + if(object[key] == null) object[key] = ( + i + 1 == path.length ? value : {} + ) + object = object[key] + } } \ No newline at end of file