let x = {
"name": undefined,
"value": "tr",
"prop1": undefined,
"prop2": "test",
"prop3": 123
};
I need to find the number of properties that are undefined, so in this case 2.
Thank you
let x = {
"name": undefined,
"value": "tr",
"prop1": undefined,
"prop2": "test",
"prop3": 123
};
I need to find the number of properties that are undefined, so in this case 2.
Thank you
2
Answers
With regular JS:
Good comments pointed out that we can indeed immediately filter; more efficient:
With Lodash
You can use
_.countBy()
to get an object (counts
) that contains the number of time a value appears in the the original object (data
). You can then get the number ofundefined
values from thecounts
object: