其他分享
首页 > 其他分享> > JS的对象

JS的对象

作者:互联网

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>js对象</title>
</head>
<body>
<script>
// 1. new

var obj1 = new Object()
obj1.name="zhangsan"
obj1.age = 18
obj1.address = "中国山东临沂"
alert(obj1.name+","+obj1.age+","+obj1.address)
console.log(obj1)

 

// 2. {}
var obj2 = {
name:"guoba",
age:22,
address:"璃月万民堂",
showmessage:function(message){
console.log(message)
}
}
obj2.sex="男"
console.log(obj2)
obj2.showmessage("你好,锅巴!")


//this在函数外代表当前对象,在函数里面谁调用它,它就代表谁


// 创建数组,长度不固定,数据类型不固定
var arr = [1,2,3,4,5,56]
arr[6] = "zhangsan"
//遍历
for(i = 0;i<arr.length;i++){
console.log(arr[i])
}

 

 

 

 

 

 


</script>
</body>
</html>

标签:obj1,arr,obj2,console,log,对象,JS,var
来源: https://www.cnblogs.com/guobabiancheng/p/16191735.html