常用的判断数组,空对象
来源:互联网 发布:淘宝二楼为何没有了 编辑:程序博客网 时间:2024/06/16 02:16
// var a = "";
// var a = " ";
// var a = null;
// var a = undefined;
// var a = [];
// var a = {};
// var a = NaN;
if(a === undefined) { // 只能用 === 运算来测试某个值是否是未定义的
console.log("为undefined");
}
if(a == null) { // 等同于 a === undefined || a === null
console.log("为null");
}
// String
if(a == "" || a == null || a == undefined){ // "",null,undefined
console.log("为空");
}
if(!a){ // "",null,undefined,NaN
console.log("为空");
}
if(!$.trim(a)){ // "",null,undefined
console.log("为空");
}
// Array
if(a.length == 0){ // "",[]
console.log("为空");
}
if(!a.length){ // "",[]
console.log("为空");
}
// Object {}
if($.isEmptyObject(a)){ // 普通对象使用 for...in 判断,有 key 即为 false
console.log("为空");
}
// var a = " ";
// var a = null;
// var a = undefined;
// var a = [];
// var a = {};
// var a = NaN;
if(a === undefined) { // 只能用 === 运算来测试某个值是否是未定义的
console.log("为undefined");
}
if(a == null) { // 等同于 a === undefined || a === null
console.log("为null");
}
// String
if(a == "" || a == null || a == undefined){ // "",null,undefined
console.log("为空");
}
if(!a){ // "",null,undefined,NaN
console.log("为空");
}
if(!$.trim(a)){ // "",null,undefined
console.log("为空");
}
// Array
if(a.length == 0){ // "",[]
console.log("为空");
}
if(!a.length){ // "",[]
console.log("为空");
}
// Object {}
if($.isEmptyObject(a)){ // 普通对象使用 for...in 判断,有 key 即为 false
console.log("为空");
}
阅读全文
0 0
- 常用的判断数组,空对象
- java 判断对象是否为空或者传入集合对象的是否为空,以及判断数组的长度
- js 判断数组 对象 为空
- java判断对象或者对象数组是否为空的类
- 数组判断为空的方法改进
- 数组自定义排序,判断对象是否为空!
- js 判断非空对象的方法
- 判断数组为空
- PHP数组 判断 空
- String的非空判断、Integer的非空判断、list的大小判断,对象的非空判断
- js 判断空对象 {}
- 判断对象为空
- 【JavaScript】 判断空对象
- js判断空对象
- js空对象判断
- 浅谈JavaScript空数组[]和空对象{}的布尔运算
- 判断对象是空对象
- js 判断对象为空或者不是对象的方法
- ElasticSearch安装及配置
- 学习Hadoop,需要什么基础?
- pecl安装扩展
- linux nohup和&后台运行,进程查看及终止
- Android面试题系列--3
- 常用的判断数组,空对象
- 如何让手机成为电脑使用?用OTG线即可实现
- 前端web开发的MVC模式
- Shader编程学习笔记(八)—— Surface Shader 2
- Java项目将错误写入文件【log4j】
- dwg文件转为dxf怎么转
- display:none与visibility:hidden
- shiro 加密 java sha-256
- 欢迎使用CSDN-markdown编辑器