title: Sort function with undefined value
body: <p>I have an array of object like below:</p>
  <pre><code> var stores = [
        {
          &quot;name&quot;: &quot;store3&quot;,
          &quot;ditance&quot;: 8
        },
        {
          &quot;name&quot;: &quot;Store5&quot;,
          &quot;distance&quot;: 7,
          &quot;web&quot;: {
            &quot;validateAttributes&quot;: {
              &quot;isSelectedDispostionSupported&quot;: true,
              &quot;isFutureOrderPossible&quot;: false
            }
          }
        },
        {
          &quot;name&quot;: &quot;Store1&quot;,
          &quot;distance&quot;: 12,
          &quot;web&quot;: {
            &quot;validateAttributes&quot;: {
              &quot;isSelectedDispostionSupported&quot;: true,
              &quot;isOpen&quot;: true
            }
          }
        },
        {
          &quot;name&quot;: &quot;store2&quot;,
          &quot;distance&quot;: 13,
          &quot;web&quot;: {
            &quot;validateAttributes&quot;: {
              &quot;isSelectedDispostionSupported&quot;: true,
              &quot;isOpen&quot;: true
            }
          }
        }
      ]
  </code></pre>
  <p>Expected  Result to be sort based on isopen and distance</p>
  <pre><code>[
    {
      &quot;name&quot;: &quot;Store1&quot;,
      &quot;distance&quot;: 12,
      &quot;web&quot;: {
        &quot;validateAttributes&quot;: {
          &quot;isSelectedDispostionSupported&quot;: true,
          &quot;isOpen&quot;: true
        }
      }
    },
    {
      &quot;name&quot;: &quot;store2&quot;,
      &quot;distance&quot;: 13,
      &quot;web&quot;: {
        &quot;validateAttributes&quot;: {
          &quot;isSelectedDispostionSupported&quot;: true,
          &quot;isOpen&quot;: true
        }
      }
    },
    {
      &quot;name&quot;: &quot;Store5&quot;,
      &quot;distance&quot;: 7,
      &quot;web&quot;: {
        &quot;validateAttributes&quot;: {
          &quot;isSelectedDispostionSupported&quot;: true,
          &quot;isFutureOrderPossible&quot;: false
        }
      }
    },
    {
      &quot;name&quot;: &quot;store3&quot;,
      &quot;ditance&quot;: 8
    }
  ]
  </code></pre>
  <p>Need to sort an array based on isOpen and distance  .The challenge is some object have web property and some object don't have. Even if web available sometimes isOpen won't their. I have tried the below approch it's not working</p>
  <pre><code>const sorter = (a, b) =&gt; {
                  if (a.web) {
                    if (a.web.validateAttributes) {
                      if (a.web.validateAttributes.isOpen) {
                        return 1;
                      } else if (b.web.validateAttributes.isOpen) {
                        return -1;
                      } else {
                        return 1;
                      };
                    } else {
                      return 1;
                    }
                   
                  } else {
                    return 1;
                  }
                };
    stores.sort(sorter);
  </code></pre>