Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to match an empty dictionary in Javascript?

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 ?

like image 351
João Pinto Jerónimo Avatar asked May 20 '11 13:05

João Pinto Jerónimo


People also ask

How do you check if a dictionary is empty in JS?

We can use Object. keys(myDict). length to get the size of the dictionary and check if it's empty ( === 0 ).

Is object empty JavaScript?

return Object.keys(obj).length === 0 ; This is typically the easiest way to determine if an object is empty.

How do you check if an object is empty in TypeScript?

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.


1 Answers

function isEmpty(obj) {   return Object.keys(obj).length === 0; } 
like image 142
Raynos Avatar answered Oct 05 '22 03:10

Raynos