A-A+
js判断数组是否为空程序代码
本文章给大家简单介绍js判断数组为空或数组元素为空的程序,有需要了解的朋友可参考。
例1,代码如下:
- if(tt==null || tt==""){
- alert("kong");
- } else {
- alert("bukong");
- }
例2,代码如下:
- var is = function (obj,type) {
- return (type === "Null" && obj === null) ||
- (type === "Undefined" && obj === void 0 ) ||
- (type === "Number" && isFinite(obj)) ||
- Object.prototype.toString.call(obj).slice(8,-1) === type;
- }
数组某个元素是否为空.
1.如果是数组元素不存在 if (arr[x] == undefined) 判断.
2.如果是元素里的内容为空值,那就需要根据你填充数组的值来做判断,代码如下:
var b = new Array (1,null,'')
console.log(b[1] == null); //填充值为null的元素
console.log(b[2] == ''); //填充值为空('')的元素
console.log(b[3] == undefined); //判断不存在的元素