title: Better way to Get Property Than using Lodash
body: <p>So we have this crap all over in our code, IMO too much lodash.  For example:</p>
  <pre><code>const profileId = _.get(account, 'profileId', null);
  const player = _.get(someCustomObject, 'player'); // Why??????  why not just someCustomObject.player?
  </code></pre>
  <p>Is it me or is it ridiculous to be using lodash for everything when you can just access object properties by the object!  In general we're using lodash and it's overkill in many places and makes the code way more verbose and hard to read.</p>
  <p>In this case, we don't really need lodash either:</p>
  <pre><code>const profileId = _.get(account, 'profileId', null);
  </code></pre>
  <p>What would be a way to do that without lodash?  That's my question.  Here are a few thoughts:</p>
  <pre><code>const profileId = (account &amp;&amp; account.profileId) || null
  </code></pre>
  <p>Any other ideas?</p>
  <p><strong>UPDATE</strong></p>
  <p>Interesting, went with Ori's answer but just an observation here.  I wanted to remove defaulting the <code>profileId</code> to null just because I feel it's unnecessary.  But why didn't this set <code>profileId</code> to the account object?</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const account = {};
  const game = { player: 'Sam' }
  
  console.log(`account: ${account}`);
  
  const { profileId } = account || {};
  const { player } = game || {};
  
  console.log(`profileId: ${profileId} // why is this undefined if account has value {}???`);
  console.log(`player: ${player}`);</code></pre>
  </div>
  </div>
  </p>
  <p>Even though account is set to a literal, I still get <code>undefined</code> for <code>profileId</code> above.  That's weird..?</p>
  <p><em>FINAL SOLUTION</em>
  (run this in <a href="https://codepen.io" rel="nofollow noreferrer">codepen.io</a> since you'll need lodash loaded)</p>
  <pre><code>console.log(&quot; Example Clean Code without Lodash&quot;)
  console.log('===============================')
  
  let account = {};
  const game = { player: 'Sam' }
  
  console.log(`account: ${account}`);
  
  const { profileId = null } = account;
  const { player } = game || {};
  
  console.log(`profileId: ${profileId}`);
  console.log(`player: ${player}`);
  
  /* using IIFE so profileId doesn't conflict with example above */
  (() =&gt; {
    console.log(&quot;Example using unnecessary Lodash&quot;)
    console.log('===============================')
  
    let profileId = _.get(account, 'profileId', null);
    const game = { player: 'Sam' } 
  
    console.log(`account2: ${account}`);
  
    const { player } = game || {};
  
    console.log(`profileId: ${profileId}`);
    console.log(`player: ${player}`);
  })();
  </code></pre>