How to use Lodash compact function?
Muhammad Harith Zainudin
Posted on May 29, 2022
Note: This tutorial also exist in my GitHub
Compact function will remove all falsey values in the array that you provided
Falsey values in javascript are something that evaluates to FALSE.
There are only six falsey values in JavaScript: undefined, null, NaN, 0, "" (empty string), and false.
How to use it? Simple.
const falseyValues = ["", null, undefined, 0, "Harith", "Malaysia"];
const cleanWords = _.compact(data.randomWord)
console.log(cleanWords)
It will remove all the falsey values in the array that we provided. Simple as that
Thank you for reading :D
Psstt pstt :p
Do consider to love this article ❤️ and follow me! Why not right? It's FREE~
I would really appreciate it 👨🏻💻
Will be posting more on things related to AWS, Javascript, Python, Serverless and more!
💖 💪 🙅 🚩
Muhammad Harith Zainudin
Posted on May 29, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.