js判断对象数组等是否为空


 //是否为空
  /**
   * null undefined NaN false " " {} [] 为空 
   * 为空 true 不为空 false   
   * @param {*} value 参数
   * 
   */
  isEmpty(value) {
    let a = false;
    if (Object.prototype.toString.call(value) == "[object Array]") {
      a = value.length == 0 ? true : false;
    } else if (Object.prototype.toString.call(value) == "[object Object]") {
      a = Object.keys(value).length == 0 ? true : false;
    } else if (Object.prototype.toString.call(value) == "[object String]") {
      a = value.replace('/s', "").length == 0 ? true : false;
    } else if (Object.prototype.toString.call(value) == "[object Number]") {
      a = isNaN(value) ? true : false;
    } else if (Object.prototype.toString.call(value) == "[object Null]") {
      a = true;
    } else if (Object.prototype.toString.call(value) == "[object Undefined]") {
      a = true;
    } else if (Object.prototype.toString.call(value) == "[object Boolean]") {
      a = value ? false : true;
    }
    return a;
  }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM