arr[0] = '张三'
arr[1] = 18
arr[2] = "男"
console.log(arr) //["张三", 18, "男"]
arr["name"] = '张三'
arr["age"] = 18
arr["sex"] = "男"
console.log(arr) //[name: "张三", age: 18, sex: "男"]
person = new Object();
person.firstname = "John";
person.lastname = "Doe";
person.age = 50;
person.eyecolor = "blue";
console.log(person) //{firstname: "John",
lastname: "Doe", age: 50, eyecolor: "blue"}
person={firstname:"John",lastname:"Doe",age:50,eyecolor:"blue"}
console.log(person) //{firstname: "John", lastname: "Doe", age: 50, eyecolor: "blue"}
//使用对象构造器
function person(firstname,lastname,age,eyecolor){
this.firstname=firstname;
this.lastname=lastname;
this.age=age;
this.eyecolor=eyecolor;
}
myFather=new person("John","Doe",50,"blue");
myMother=new person("Tim","li",48,"white");
console.log(myFather) //person {firstname: "John", lastname: "Doe", age: 50, eyecolor: "blue"}
console.log(myMother) //person {firstname: "Tim", lastname: "li", age: 48, eyecolor: "white"}
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有