From the node REPL thing,
> d = {} {} > d === {} false > d == {} false
Given I have an empty dictionary, how do I make sure it is an empty dictionary ?
We can use Object. keys(myDict). length to get the size of the dictionary and check if it's empty ( === 0 ).
return Object.keys(obj).length === 0 ; This is typically the easiest way to determine if an object is empty.
To check if an object is empty in TypeScript:Use the Object. keys() method to get an array of the object's keys. Access the length property on the array. If the length property is equal to 0 , the object is empty.
function isEmpty(obj) { return Object.keys(obj).length === 0; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With