相关文章推荐
英俊的硬币  ·  OpenCV ...·  6 月前    · 
体贴的拐杖  ·  installation - ...·  1 年前    · 
阳刚的数据线  ·  Oops!!! - 简书·  1 年前    · 

js 判断字典为空

在 JavaScript 中,可以使用如下代码来判断字典是否为空:

var object = {};
if (Object.keys(object).length === 0) {
  console.log("The object is empty");
} else {
  console.log("The object is not empty");

上面的代码中,我们使用了 Object.keys() 方法来获取对象的 key 列表,然后使用数组的 length 属性来判断该列表的长度是否为 0。如果长度为 0,说明该对象为空;否则说明该对象不为空。

  •