JavaScript学习笔记之对象
对象
JavaScript中的对象是一种无序的数据集合
//举例说明
var lh={
name:‘lh’,
age:‘19’};
console.log(lh.height);//返回undefined
如果访问对象"lh"中不存在的元素,会返回”undefined"
//举例说明
var lh={
name:‘lh’,
age:‘19’};
console.log(lh.height);//返回undefined
而且由于JavaScript的对象是动态类型,所以你可以修改对象lh中的元素
//举例说明
var lh={
name:‘lh’,
age:‘19’};
lh.height=173;
console.log(lh.height);//输出173
delete lh.age;
console.log(lh.age);//返回undefined
检测JavaScript的额对象是否拥有某个元素,可以使用in方法
//举例说明
var lh={
name:‘lh’,
age:‘19’};
var i=‘height’ in lh;
console.log(i);//输出false
var j=‘age’ in lh;
console.log(j);//输出true