Js判断参数(String,Array,Object)是否为undefined或者值为空

出处:http://www.jb51.net/article/42713.htm

有空整理下


var isEmptyValue = function(value) {            var type;

            if(value == null) { // 等同于 value === undefined || value === null
                return true;
            }
            type = Object.prototype.toString.call(value).slice(8, -1);
            switch(type) {
            case 'String':
                return !$.trim(value);
            case 'Array':
                return !value.length;
            case 'Object':
                return $.isEmptyObject(value); // 普通对象使用 for...in 判断,有 key 即为 false
            default:
                return false; // 其他对象均视作非空
            }
        }

你可能感兴趣的:(前端日记)