当前位置:网站首页>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' ]
边栏推荐
猜你喜欢
Missing monitoring: ZABBIX monitors the status of Eureka instance
树莓派3B更新vim
Crawling exercise: Notice of crawling Henan Agricultural University
杰理之BLE【篇】
LeetCode 78:子集
NiO programming introduction
Excel的相关操作
Raspberry pie serial port login and SSH login methods
巴比特 | 元宇宙每日必读:中国互联网企业涌入元宇宙的群像:“只有各种求生欲,没有前瞻创新的雄心”...
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
随机推荐
leetcode841. 钥匙和房间(中等)
Path analysis model
Excel的相关操作
杰理之BLE【篇】
首发织梦百度推送插件全自动收录优化seo收录模块
Go learning -- implementing generics based on reflection and empty interfaces
Week6 weekly report
Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
leetcode1020. Number of enclaves (medium)
Applied stochastic process 01: basic concepts of stochastic process
TypeScript 函数定义
NiO programming introduction
Refer to how customer push e-commerce does content operation
[online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code
Word delete the contents in brackets
杰理之如若需要大包发送,需要手机端修改 MTU【篇】
SSM学习
学go之路(二)基本类型及变量、常量
Simple use of JWT
(4) Web security | penetration testing | network security web site source code and related analysis