众所周知,我是嫖过来的,所以先上原文链接,因为以后不好找
https://blog.csdn.net/zhangjing0320/article/details/81230170
直接跳转
var obj = {};
1、toString(推荐)
Object.prototype.toString.call(obj) === '[object Object]'
2、constructor
obj.constructor === Object
3、instanceof 需要注意的是由于数组也是对象,因此用 arr instanceof Object 也为true。
obj instanceof Object
4、typeof
typeof obj === Object
// 根据typeof判断对象也不太准确
表达式 返回值
typeof undefined 'undefined'
typeof null 'object'
typeof true 'boolean'
typeof 123 'number'
typeof "abc" 'string'
typeof function() {} 'function'
typeof {} 'object'
typeof [] 'object'
5、$.isPlainObject()
$.isPlainObject(obj)
对象添加和删除属性
var obj= {}
obj.address=“shenzhen”
var obj= {
height: 180,
long: 180,
weight: 180,
hobby: {
ball: 'good',
music: 'nice'
}
}
delete obj.hobby