当前位置:网站首页>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' ]
边栏推荐
- TS基础篇
- 微信脑力比拼答题小程序_支持流量主带最新题库文件
- NiO programming introduction
- Cif10 actual combat (resnet18)
- 呆错图床系统源码图片CDN加速与破解防盗链功能
- Wechat brain competition answer applet_ Support the flow main belt with the latest question bank file
- Uncaught typeerror: cannot red properties of undefined (reading 'beforeeach') solution
- Path analysis model
- OpenGL ES 学习初识(1)
- 【mysql学习笔记30】锁(非教程)
猜你喜欢

作者已死?AI正用艺术征服人类

1091: two or three things in childhood (multi instance test)

mysql如何合并数据

Leetcode59. spiral matrix II (medium)

数字IC设计笔试题汇总(一)

首发织梦百度推送插件全自动收录优化seo收录模块

JDBC learning notes

Cookie技术&Session技术&ServletContext对象

Wechat official account infinite callback authorization system source code, launched in the whole network

leetcode841. Keys and rooms (medium)
随机推荐
数字IC设计笔试题汇总(一)
WPF之MVVM
配置树莓派接入网络
leetcode59. 螺旋矩阵 II(中等)
Excel的相关操作
TS基础篇
NFT on fingertips | evaluate ambire on G2, and have the opportunity to obtain limited edition collections
Bio model realizes multi person chat
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
微信脑力比拼答题小程序_支持流量主带最新题库文件
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
Yield method of tread
1189. Maximum number of "balloons"
#systemverilog# 可综合模型的结构总结
The first Baidu push plug-in of dream weaving fully automatic collection Optimization SEO collection module
JDBC学习笔记
杰理之BLE【篇】
Memory error during variable parameter overload
Interface automation test framework: pytest+allure+excel
Cookie技术&Session技术&ServletContext对象