美文网首页
判空函数

判空函数

作者: 暖暖1500 | 来源:发表于2022-02-21 19:01 被阅读0次
    const isEmpty = (value) => {
      let tmp = value;
      if (value === null || value === undefined) {
        tmp = '';
    
        // true/false will be translated to "ture"/"false", so, boolean type always not empty
      } else if (typeof value === 'number' || typeof value === 'boolean') {
        tmp = String(value);
      }
    
      let ret = tmp;
      if (typeof tmp === 'string' || Array.isArray(tmp)) {
        ret = tmp.length;
      } else if (typeof tmp === 'object') {
        ret = Object.keys(tmp).length;
      }
    
      return !ret;
    };
    

    相关文章

      网友评论

          本文标题:判空函数

          本文链接:https://www.haomeiwen.com/subject/jblylrtx.html