[JavaScript] javascript 判断对象是否为空 →→→→→进入此内容的聊天室

来自 , 2020-09-17, 写在 JavaScript, 查看 122 次.
URL http://www.code666.cn/view/78211247
  1. function is_empty(obj) {
  2.   "use strict";
  3.   if (Object.prototype.toString.call(obj) === '[object Object]') {
  4.     // Assume if it has a length property with a non-zero value
  5.     // that that property is correct.
  6.     if (obj.length && obj.length > 0){ return false; }
  7.     if (obj.length && obj.length === 0){return true; }
  8.  
  9.     for (var key in obj) {
  10.       if (Object.prototype.hasOwnProperty.call(obj, key)) { return false; }
  11.     }
  12.   } else if (Object.prototype.toString.call(obj) === '[object Array]') {
  13.     if (obj.length && obj.length > 0){ return false; }
  14.   }
  15.   return true;
  16. }
  17. //javascript/5790

回复 "javascript 判断对象是否为空"

这儿你可以回复上面这条便签

captcha