title: In JavaScript, how to tell that an array element is empty vs undefined?
body: <p>What are all the methods that can do that?</p>
  
  <p>I only know of two methods. To summarize, to find whether <code>arr[1]</code> is empty or undefined, use </p>
  
  <pre><code>1 in arr
  </code></pre>
  
  <p>or </p>
  
  <pre><code>Object.keys(arr).includes("1")
  </code></pre>
  
  <p>but the second method may possibly create a big array to begin with.</p>
  
  <pre><code>// running inside of Node 6.11.0
  
  // Methods that works:
  &gt; a = Array(3)
  [ , ,  ]
  
  &gt; b = Array.from({length:3})
  [ undefined, undefined, undefined ]
  
  &gt; 1 in a
  false
  &gt; 1 in b
  true
  
  &gt; Object.keys(a).includes("1")
  false
  &gt; Object.keys(b).includes("1")
  true
  
  // Method that doesn't
  &gt; a[1]
  undefined
  &gt; b[1]
  undefined
  
  &gt; a[1] === undefined
  true
  &gt; b[1] === undefined
  true
  </code></pre>