数组/对象
前端
0
700
0
发表于: 2020-02-24 15:48:58
简介: 暂无~
数组
- 创建数组
- var arr = new Array()
- var arr = []
- 索引数组
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"}
最后更新于:2021-02-16 21:01:55
欢迎评论留言~
0/400
支持markdownComments | 0 条留言
登录
按时间
按热度
目前还没有人留言~