please I need help with this
const obj = {a="", b="good", c=false, d="", e="excellent"}
I just want to know total empty and false. where my answer is suppose to be 3.
const obj = {a="", b="good", c=false, d="", e="excellent"}
for (let k in obj) {
if (obj[k] === '' || obj[k] === false) {
//console.log(k);
}
}
Any pointers will be greatly appreciated
THank you
4
Answers
You could just make an array and put the keys that are empty into it. That way, at the end of the program, the length of the array will be the number of empty elements.
Or you could simply add a variable that increments whenever it finds an empty value.
Hope this helps
You can
reduce
overObject.values
.To get the actual values that were falsy, use
Array#filter
instead.Here’s a one liner to archieve your result set using
Array.Prototype.filter
: