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!
Top comments (0)