Falsy values in JavaScript are false, null, 0, "", undefined, and NaN.
Hint:
// regular for loop that I use which is
for (let i = 0; i < arr.length: i++) { // which reads indexes.
// This new method while watching videos which is
for (let elem of arr {
console.log(elem);
}
// basically its a loop that goes through all the elements themselves instead of going through the indexes.
if (false) {
console.log("hello")
; // it wont call out hello because false is a falsey value
Answer:
function bouncer(arr) {
let result = [];
for (let elem of arr) {
if (elem) result.push(elem);
}
return result;
}
bouncer([7, "ate", "", false, 9]); // will display [7, "ate", 9]
Top comments (0)
Subscribe
For further actions, you may consider blocking this person and/or reporting abuse
Top comments (0)