title: Create an empty object at deep path with lodash
body: <p>I need to create an empty object at a deep path but only if it is not exist and return a reference to that object.</p>
  
  <p>This can be accomplished by using <code>_.has</code>, <code>_.set</code> and then <code>_.get</code></p>
  
  <pre><code>let path = 'some.deep.path';
  
  if (!_.has(object, path)) {
      _.set(object, path, {});
  }
  
  let descendant = _.get(object, path);
  </code></pre>
  
  <p>What I would like instead, is to avoid repeating the <code>object</code>, <code>path</code> (or introducing the <code>path</code> variable to avoid repeating the <code>path</code> value)</p>
  
  <p>I wonder if there's a way to do that without extra function/library.</p>
  
  <hr>
  
  <h3>List of lodash methods that accept or deal with a path. Alphabetically</h3>
  
  <p>This includes methods that deal with arrays/collections and accept the <code>_.property</code> iteratee/predicate shorthand, i.e. when a string is provided as an argument, it is passed over to the <code>_.property</code> method that creates a function which returns the value at path of a given object (that was given by the main function, e.g. <code>_.map</code>).</p>
  
  <p><strong>Array</strong></p>
  
  <ul>
  <li><em>v4.0.0</em> <a href="https://lodash.com/docs#differenceBy" rel="noreferrer">_.differenceBy</a>(array, [values], [iteratee=_.identity])</li>
  <li><em>v3.0.0</em> <a href="https://lodash.com/docs#dropRightWhile" rel="noreferrer">_.dropRightWhile</a>(array, [predicate=_.identity])</li>
  <li><em>v3.0.0</em> <a href="https://lodash.com/docs#dropWhile" rel="noreferrer">_.dropWhile</a>(array, [predicate=_.identity])</li>
  <li><em>v1.1.0</em> <a href="https://lodash.com/docs#findIndex" rel="noreferrer">_.findIndex</a>(array, [predicate=_.identity], [fromIndex=0])</li>
  <li><em>v2.0.0</em> <a href="https://lodash.com/docs#findLastIndex" rel="noreferrer">_.findLastIndex</a>(array, [predicate=_.identity], [fromIndex=array.length-1])</li>
  <li><em>v4.0.0</em> <a href="https://lodash.com/docs#intersectionBy" rel="noreferrer">_.intersectionBy</a>([arrays], [iteratee=_.identity])</li>
  <li><em>v4.0.0</em> <a href="https://lodash.com/docs#sortedIndexBy" rel="noreferrer">_.sortedIndexBy</a>(array, value, [iteratee=_.identity])</li>
  <li><em>v4.0.0</em> <a href="https://lodash.com/docs#sortedLastIndexBy" rel="noreferrer">_.sortedLastIndexBy</a>(array, value, [iteratee=_.identity])</li>
  <li><em>v3.0.0</em> <a href="https://lodash.com/docs#takeRightWhile" rel="noreferrer">_.takeRightWhile</a>(array, [predicate=_.identity])</li>
  <li><em>v3.0.0</em> <a href="https://lodash.com/docs#takeWhile" rel="noreferrer">_.takeWhile</a>(array, [predicate=_.identity])</li>
  <li><em>v4.0.0</em> <a href="https://lodash.com/docs#unionBy" rel="noreferrer">_.unionBy</a>([arrays], [iteratee=_.identity])</li>
  <li><em>v4.0.0</em> <a href="https://lodash.com/docs#uniqBy" rel="noreferrer">_.uniqBy</a>(array, [iteratee=_.identity])</li>
  <li><em>v4.0.0</em> <a href="https://lodash.com/docs#unionBy" rel="noreferrer">_.xorBy</a>([arrays], [iteratee=_.identity])</li>
  <li><em>v4.1.0</em> <a href="https://lodash.com/docs#zipObjectDeep" rel="noreferrer">_.zipObjectDeep</a>([props=[]],  [values=[]])</li>
  </ul>
  
  <p><strong>Collection</strong></p>
  
  <ul>
  <li><em>v0.5.0</em> <a href="https://lodash.com/docs#countBy" rel="noreferrer">_.countBy</a>(collection, [iteratee=_.identity])</li>
  <li><em>v0.1.0</em> <a href="https://lodash.com/docs#every" rel="noreferrer">_.every</a>(collection, [predicate=_.identity])</li>
  <li><em>v0.1.0</em> <a href="https://lodash.com/docs#filter" rel="noreferrer">_.filter</a>(collection, [predicate=_.identity])</li>
  <li><em>v0.1.0</em> <a href="https://lodash.com/docs#find" rel="noreferrer">_.find</a>(collection, [predicate=_.identity])</li>
  <li><em>v0.1.0</em> <a href="https://lodash.com/docs#groupBy" rel="noreferrer">_.groupBy</a>(collection, [iteratee=_.identity])</li>
  <li><em>v4.0.0</em> <a href="https://lodash.com/docs#invokeMap" rel="noreferrer">_.invokeMap</a>(collection, path, [args])</li>
  <li><em>v0.1.0</em> <a href="https://lodash.com/docs#map" rel="noreferrer">_.map</a>(collection, [iteratee=_.identity])</li>
  <li><em>v3.0.0</em> <a href="https://lodash.com/docs#partition" rel="noreferrer">_.partition</a>(collection, [predicate=_.identity])</li>
  <li><em>v0.1.0</em> <a href="https://lodash.com/docs#reject" rel="noreferrer">_.reject</a>(collection, [iteratee=_.identity])</li>
  <li><em>v0.1.0</em> <a href="https://lodash.com/docs#some" rel="noreferrer">_.some</a>(collection, [iteratee=_.identity])</li>
  </ul>
  
  <p><strong>Math</strong></p>
  
  <ul>
  <li><em>v4.0.0</em> <a href="https://lodash.com/docs#maxBy" rel="noreferrer">_.maxBy</a>(array, [iteratee=_.identity])</li>
  <li><em>v4.7.0</em> <a href="https://lodash.com/docs#meanBy" rel="noreferrer">_.meanBy</a>(array, [iteratee=_.identity])</li>
  <li><em>v4.0.0</em> <a href="https://lodash.com/docs#minBy" rel="noreferrer">_.minBy</a>(array, [iteratee=_.identity])</li>
  <li><em>v4.0.0</em> <a href="https://lodash.com/docs#sumBy" rel="noreferrer">_.sumBy</a>(array, [iteratee=_.identity])</li>
  </ul>
  
  <p><strong>Object</strong></p>
  
  <ul>
  <li><em>v1.0.0</em> <a href="https://lodash.com/docs#at" rel="noreferrer">_.at</a>(object, [paths])</li>
  <li><em>v1.1.0</em> <a href="https://lodash.com/docs#findKey" rel="noreferrer">_.findKey</a>(object, [predicate=_.identity])</li>
  <li><em>v2.0.0</em> <a href="https://lodash.com/docs#findLastKey" rel="noreferrer">_.findLastKey</a>(object, [predicate=_.identity])</li>
  <li><em>v3.7.0</em> <a href="https://lodash.com/docs#get" rel="noreferrer">_.get</a>(object, path, [defaultValue])</li>
  <li><em>v0.1.0</em> <a href="https://lodash.com/docs#has" rel="noreferrer">_.has</a>(object, path)</li>
  <li><em>v4.0.0</em> <a href="https://lodash.com/docs#hasIn" rel="noreferrer">_.hasIn</a>(object, path)</li>
  <li><em>v4.0.0</em> <a href="https://lodash.com/docs#invoke" rel="noreferrer">_.invoke</a>(object, path, [args])</li>
  <li><em>v2.4.0</em> <a href="https://lodash.com/docs#mapValues" rel="noreferrer">_.mapValues</a>(object, [iteratee=_.identity])</li>
  <li><em>v0.1.0</em> <a href="https://lodash.com/docs#omit" rel="noreferrer">_.omit</a>(object, [paths])</li>
  <li><em>v0.1.0</em> <a href="https://lodash.com/docs#pick" rel="noreferrer">_.pick</a>(object, [paths])</li>
  <li><em>v0.1.0</em> <a href="https://lodash.com/docs#result" rel="noreferrer">_.result</a>(object, path, [defaultValue])</li>
  <li><em>v3.7.0</em> <a href="https://lodash.com/docs#set" rel="noreferrer">_.set</a>(object, path, value)</li>
  <li><em>v4.0.0</em> <a href="https://lodash.com/docs#setWith" rel="noreferrer">_.setWith</a>(object, path, value, [customizer])</li>
  <li><em>v4.0.0</em> <a href="https://lodash.com/docs#unset" rel="noreferrer">_.unset</a>(object, path)</li>
  <li><em>v4.6.0</em> <a href="https://lodash.com/docs#update" rel="noreferrer">_.update</a>(object, path, updater)</li>
  <li><em>v4.6.0</em> <a href="https://lodash.com/docs#updateWith" rel="noreferrer">_.updateWith</a>(object, path, updater, [customizer])</li>
  </ul>
  
  <p><strong>Util</strong></p>
  
  <ul>
  <li><em>v4.0.0</em> <a href="https://lodash.com/docs#iteratee" rel="noreferrer">_.iteratee</a>([func=_.identity])</li>
  <li><em>v3.2.0</em> <a href="https://lodash.com/docs#matchesProperty" rel="noreferrer">_.matchesProperty</a>(path, srcValue)</li>
  <li><em>v3.7.0</em> <a href="https://lodash.com/docs#method" rel="noreferrer">_.method</a>(path, [args])</li>
  <li><em>v3.7.0</em> <a href="https://lodash.com/docs#methodOf" rel="noreferrer">_.methodOf</a>(object, [args])</li>
  <li><em>v2.4.0</em> <a href="https://lodash.com/docs#property" rel="noreferrer">_.property</a>(path)</li>
  <li><em>v3.0.0</em> <a href="https://lodash.com/docs#propertyOf" rel="noreferrer">_.propertyOf</a>(object)</li>
  <li><em>v4.0.0</em> <a href="https://lodash.com/docs#toPath" rel="noreferrer">_.toPath</a>(value)</li>
  </ul>
  
  <p><strong>Seq</strong></p>
  
  <p>Chained methods, i.e. methods that are called in a <strong>seq</strong>uence, e.g.:</p>
  
  <pre><code>_(value).chained().method().value();
  </code></pre>
  
  <ul>
  <li><em>v1.0.0</em> <a href="https://lodash.com/docs#prototype-at" rel="noreferrer">_.prototype.at</a>([paths])</li>
  </ul>