# How to remove null from the array element?

**URL:** <https://forum.freecodecamp.org/t/how-to-remove-null-from-the-array-element/144563>\
**Category:** General\
**Created:** [August 29, 2017, 2:06pm UTC](https://forum.freecodecamp.org/t/how-to-remove-null-from-the-array-element/144563 "2017-08-29T14:06:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![NikhilAgrawal-1999](https://avatars.discourse-cdn.com/v4/letter/n/b9e5f3/32.png) [@NikhilAgrawal-1999](https://forum.freecodecamp.org/u/NikhilAgrawal-1999)\
**Post date:** [August 29, 2017, 2:06pm UTC](https://forum.freecodecamp.org/t/how-to-remove-null-from-the-array-element/144563/1 "2017-08-29T14:06:45Z")

</div>

```auto
function bouncer(arr) {
  // Don't show a false ID to this bouncer.
  arr = arr.filter(function (val){
    switch(val){
      case false : 
      case null : 
      case 0 :
      case "" :
      case undefined : 
      case NaN :
        return 0;
      default :
        return 1;
        
    }
  });
  
  return arr;
}

bouncer([false, null, 0, NaN, undefined, ""]);

```

---

<div class="post-metadata">

**Author:** ![ArielLeslie](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/arielleslie/32/264841_2.png) [@ArielLeslie](https://forum.freecodecamp.org/u/ArielLeslie)\
**Post date:** [August 29, 2017, 2:26pm UTC](https://forum.freecodecamp.org/t/how-to-remove-null-from-the-array-element/144563/2 "2017-08-29T14:26:44Z")

</div>

I’ve edited your post for readability. When you enter a code block into the forum, remember to precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See [this post](http://forum.freecodecamp.com/t/forum-code-formatting/25574) to find the backtick on your keyboard.

![markdown_Forums](https://sea3.discourse-cdn.com/freecodecamp/uploads/default/original/3X/4/b/4b9a26f0c243380dd84935f4e29b92e3ecee8d05.gif)

---

<div class="post-metadata">

**Author:** ![PortableStick](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/portablestick/32/65591_2.png) [@PortableStick](https://forum.freecodecamp.org/u/PortableStick)\
**Post date:** [August 29, 2017, 2:27pm UTC](https://forum.freecodecamp.org/t/how-to-remove-null-from-the-array-element/144563/3 "2017-08-29T14:27:47Z")

</div>

Remember this because it will probably come up as an interview question. `NaN` never equals itself.

```auto
NaN === NaN; false
NaN == NaN; false

```

There is a handy function that can tell you when something is `NaN`. It’s called… wait for it… [isNaN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/isNaN).

---

<div class="post-metadata">

**Author:** ![ArielLeslie](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/arielleslie/32/264841_2.png) [@ArielLeslie](https://forum.freecodecamp.org/u/ArielLeslie)\
**Post date:** [August 29, 2017, 2:28pm UTC](https://forum.freecodecamp.org/t/how-to-remove-null-from-the-array-element/144563/4 "2017-08-29T14:28:47Z")

</div>

This is a common misunderstanding with the Falsy Bouncer. You _can_ make a solution for this challenge which tests against a hardcoded list of falsy values, but it misses the point of the exercise. The concept of values being “falsy” isn’t something made up by Free Code Camp for the purposes of this challenge, but rather a quality that values have in programming languages. A value is falsy if the language treats the value as `false` when it is evaluated as a boolean. This means that `Boolean(someFalsyValue)` is `false` but also that we can use it in a conditional like `if (someFalsyValue)`. We can also talk about values being “truthy”. As I’m sure you’ve guessed, truthy values evaluate to `true` in a boolean of logical context.

```javascript
if (someFalsyValue) {
    // this code block is not entered
}
else if (someTruthyValue) {
    // this code block is entered and executed
}

```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 6:03pm UTC](https://forum.freecodecamp.org/t/how-to-remove-null-from-the-array-element/144563/6 "2021-01-16T18:03:19Z")

</div>

Closed on January 16, 2021, 6:03pm UTC


