How to check if a map is empty in JavaScript

1 Answer

0 votes
const mp = new Map();

console.log(mp.size); 

console.log(mp.size === 0 ? "empty" : "not empty");




/*
run:
 
0
"empty"
  
*/
  

 



answered Jun 2, 2022 by avibootz
edited Jun 2, 2022 by avibootz

Related questions

1 answer 156 views
156 views asked Oct 11, 2022 by avibootz
1 answer 144 views
144 views asked Oct 11, 2022 by avibootz
1 answer 136 views
1 answer 129 views
1 answer 143 views
143 views asked Apr 13, 2020 by avibootz
1 answer 148 views
...