当前位置:网站首页>js对象获取属性的方法(.和[]方式)
js对象获取属性的方法(.和[]方式)
2022-07-06 07:19:00 【大象与小蚂蚁】
js对象获取属性有两种方法:1.通过.的方式 2. 通过[]方式
// 通过.方式获取属性值,key是静态的
var aa = {
name: "zhang", age: 18};
console.log(aa.name);
// 通过[]获取属性值, key是动态的,可以是字符串,或者数字的形式
var bb = {
"apple": 3, "pear": 2}
var cc = {
1: "number1", 2: "number2"}
console.log(bb["apple"]);
console.log(cc[1]); // 注意这里的写法跟数组容易混淆,cc仍是对象,不是数组
// 获取对象所有key的方法
console.log(Object.keys(bb)); // 输出[ 'apple', 'pear' ]
边栏推荐
- Openjudge noi 2.1 1749: Digital Square
- NiO programming introduction
- Configure raspberry pie access network
- The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
- idea控制台彩色日志
- 【mysql学习笔记30】锁(非教程)
- Leetcode59. spiral matrix II (medium)
- mysql如何合并数据
- How can word delete English only and keep Chinese or delete Chinese and keep English
- Thought map of data warehouse construction
猜你喜欢
The ECU of 21 Audi q5l 45tfsi brushes is upgraded to master special adjustment, and the horsepower is safely and stably increased to 305 horsepower
杰理之开发板上电开机,就可以手机打开 NRF 的 APP【篇】
Kubernetes cluster builds ZABBIX monitoring platform
Oracle database 11gr2 uses TDE transparent data encryption to report an error ora28353. If you run to close the wallet, you will report an error ora28365. If you run to open the wallet, you will repor
leetcode1020. 飞地的数量(中等)
Cookie技术&Session技术&ServletContext对象
JDBC learning notes
SSM学习
Path analysis model
leetcode841. 钥匙和房间(中等)
随机推荐
Solution to the problem of breakthrough in OWASP juice shop shooting range
ORACLE列转行--某字段按指定分隔符转多行
变量的命名规则十二条
[JDBC] quick start tutorial
Configure raspberry pie access network
Crawling exercise: Notice of crawling Henan Agricultural University
TypeScript 接口属性
作者已死?AI正用藝術征服人類
Uni app practical project
Cookie技术&Session技术&ServletContext对象
位运算异或
Missing monitoring: ZABBIX monitors the status of Eureka instance
The psychological process from autojs to ice fox intelligent assistance
Excel的相关操作
Detailed explanation | detailed explanation of internal mechanism of industrial robot
Chrome view page FPS
word中把帶有某個符號的行全部選中,更改為標題
Leetcode35. search the insertion position (simple, find the insertion position, different writing methods)
微信公众号无限回调授权系统源码 全网首发
UWA pipeline version 2.2.1 update instructions