类型
getType
getType(needle)
获取数据类型,简洁版。
返回值:String
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
needle | 待识别对象 | * |
console.log(JW.getType([]));
isEmpty
isEmpty(needle[, strict])
检测是否为空。
返回值:Boolean
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
needle | 待检测对象 | * | ||
strict | 启用严格模式。 非严格模式,以下字符串视为空: '0' 'null' 'undefined' 'false' 'NaN' | Boolean | false |
js
console.log(JW.isEmpty(0));
console.log(JW.isEmpty('0'));
console.log(JW.isEmpty('0', 1));
isFloat
isFloat(needle)
检测是否为浮点型。
返回值:Boolean
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
needle | 待检测对象 | * |
js
console.log(JW.isFloat(1));
console.log(JW.isFloat(1.1));
console.log(JW.isFloat([]));
isRealNaN
isRealNaN(needle)
检测是否为NaN
。
返回值:Boolean
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
needle | 待检测对象 | * |
js
console.log(JW.isRealNaN('NaN'));
console.log(JW.isRealNaN(NaN));
console.log(JW.isRealNaN({}));
isSet
isSet(needle)
检测是否设置,以下类型视为未设置:undefined
NaN
null
false
。
返回值:Boolean
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
needle | 待检测对象 | * |
js
console.log(JW.isSet(undefined));
console.log(JW.isSet(NaN));
console.log(JW.isSet(null));
console.log(JW.isSet(false));
console.log(JW.isSet(0));
toNumber
toNumber(needle)
转换为Number类型。
返回值:Number
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
needle | 待转换对象 | String |
js
console.log(JW.toNumber('1'));
toObject
toObject(needle)
转换为对象数据类型。
返回值:Object
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
needle | 待转换对象 | String | Array |
js
console.log(JW.toObject([1, 2, 3]));
console.log(JW.toObject('123'));
typeofStr
typeofStr(needle)
获取数据类型,冗长版。
返回值:String
参数 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
needle | 待检测对象 | * |
js
console.log(JW.typeofStr([]));
console.log(JW.typeofStr(''));