Remove Falsy Values From Array

by Matthew Day

HTML

<div class="title">Output</div>
<div id="output"></div>

CSS

* {
  font-family: 'Arial', sans-serif;
}

.title {
  font-size: 12px;
  margin-bottom: 8px;
  text-transform: uppercase;
}

#output {
  background: white;
  border: 1px solid gray;
  height: 30px;
  width: 260px;
}

JavaScript

var data = [42, 21, undefined, 50, null, 40, 1, undefined, 0, 9];
var output = document.getElementById('output');
var text = 'heythere';
data = data.filter(Boolean);
output.textContent = data;

// Based on an answer from jAndy found at http://stackoverflow.com/questions/28607451/removing-undefined-values-from-array and accessed on December 14, 2016.