JUQERY判断变量是数组还是对象
$.isArray();
$.isPlainObject();
用途: 我们通常用typeof()来判断一个变量的类型,但是这个变量是数组或是对象,在jquery里都会返回一个Object类型
所以我们需要知道它倒底是一个数组还是一个对象,其实都可以。就用上述命令判断,就可以知道:
(function($){
var obj = {
"title":"jsonparse",
"time":new Date().getTime()
};
var arr = [{"title":"jsonarr"},{"time":new Date().getTime()}];
console.log(typeof(obj));
console.log($.isArray(obj));
console.log($.isPlainObject(obj));
console.log(JSON.stringify(obj));
console.log(typeof(arr));
console.log($.isArray(arr));
console.log($.isPlainObject(arr));
console.log(JSON.stringify(arr));
})(jQuery);
浙公网安备 33010602011771号