前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >数组/对象

数组/对象

作者头像
hss
发布2022-02-25 20:10:39
1.1K0
发布2022-02-25 20:10:39
举报
文章被收录于专栏:前端卡卡西前端卡卡西

数组

  1. 创建数组
    1. var arr = new Array()
    2. var arr = []
  2. 索引数组
代码语言:javascript
复制
arr[0] = '张三'
arr[1] = 18
arr[2] = "男"
console.log(arr)    //["张三", 18, "男"]
  1. 关联数组
代码语言:javascript
复制
arr["name"] = '张三'
arr["age"] = 18
arr["sex"] = "男"
console.log(arr)    //[name: "张三", age: 18, sex: "男"]

对象

  1. 创建对象
代码语言:javascript
复制
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"}
代码语言:javascript
复制
person={firstname:"John",lastname:"Doe",age:50,eyecolor:"blue"}
console.log(person) //{firstname: "John", lastname: "Doe", age: 50, eyecolor: "blue"}
代码语言:javascript
复制
//使用对象构造器
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"}
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2020-02-24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 数组
  • 对象
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档