Remove empty, false, undefined values from array Javscript

If you want to remove all false, empty, undefined values from the Javascript array you can use the code example and methods explained in this post.

var my_arr = [4, '', 0, 10, 7, '', false, 10];

my_arr = my_arr.filter(Boolean);




Try it yourself

Use For Loop and ES6 to remove falsy values from an Array

If you are using ES6 in your project, you can easily remove empty or falsy values from an array. It is the fastest way to do that.

const input_arr = [20, 30, , , , null, 50, 40, undefined, , null, undefined];
const result = [];

for (let i of input_arr)
    i && result.push(i);




Try it yourself

Was this helpful?