---
title: Falsy Bouncer
---

 Remember to use **`Read-Search-Ask`** if you get stuck. Try to pair program  and write your own code 
###  Problem Explanation:
Remove all falsy values from an array.
#### Relevant Links
* Falsy Values
##  Hint: 1
Falsy is something which evaluates to FALSE. There are only six falsy values in JavaScript: undefined, null, NaN, 0, "" (empty string), and false of course.
> _try to solve the problem now_
##  Hint: 2
We need to make sure we have all the falsy values to compare, we can know it, maybe with a function with all the falsy values...
> _try to solve the problem now_
##  Hint: 3
Then we need to add a `filter()` with the falsy values function...
> _try to solve the problem now_
## Spoiler Alert!

**Solution ahead!**
##  Basic Code Solution:
```js
function bouncer(arr) {
let newArray = [];
for (var i = 0; i < arr.length; i++){
if (arr[i])
newArray.push(arr[i]);
}
return newArray;
}
```
 Run Code
### Code Explanation:
We create a new empty array.
We use a for cycle to iterate over all elements of the provided array (arr).
We use the if statement to check if the current element is truthy or falsy.
If the element is truthy, we push it to the new array (newArray). This result in the new array (newArray) containing only truthy elements.
We return the new array (newArray).
#### Relevant Links
* [Boolean](https://forum.freecodecamp.com/t/javascript-boolean/14311)
* [Truthy value](https://forum.freecodecamp.com/t/javascript-truthy-value/15975)
* [Falsey values](https://www.freecodecamp.org/forum/t/javascript-falsy-values/14664)
* [Array.prototype.push](https://www.freecodecamp.org/forum/t/javascript-array-prototype-push/14298)
##  Advanced Code Solution:
```js
function bouncer(arr) {
return arr.filter(Boolean);
}
```
 Run Code
### Code Explanation:
The `Array.prototype.filter` method expects a function that returns a `Boolean` value which takes a single argument and returns `true` for truthy value or `false` for falsy value. Hence we pass the built-in `Boolean` function.
#### Relevant Links
* Boolean
* Truthy
* Array.prototype.filter()
##  Credits:
If you found this page useful, you can give thanks by copying and pasting this on the main chat:
##  NOTES FOR CONTRIBUTIONS:
*  **DO NOT** add solutions that are similar to any existing solutions. If you think it is **_similar but better_**, then try to merge (or replace) the existing similar solution.
* Add an explanation of your solution.
* Categorize the solution in one of the following categories — **Basic**, **Intermediate** and **Advanced**. 