Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Remove Falsy Values from JavaScript Array</title> </head> <body> <script> // Sample array var arr = [1,2,,3,,-4,"",null,,0,,false,undefined,5,,-5,6,"",7,,]; // Performing filtration var filtered = arr.filter(elm => elm); document.write(JSON.stringify(filtered)); // Prints: [1, 2, 3, -4, 5, -5, 6, 7] </script> </body> </html>