当前位置:网站首页>js對象獲取屬性的方法(.和[]方式)
js對象獲取屬性的方法(.和[]方式)
2022-07-06 07:21: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' ]
边栏推荐
- Yield method of tread
- Multi attribute object detection on rare aircraft data sets: experimental process using yolov5
- Configure raspberry pie access network
- [online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code
- Go learning -- implementing generics based on reflection and empty interfaces
- Solution to the problem of breakthrough in OWASP juice shop shooting range
- GET/POST/PUT/PATCH/DELETE含义
- Babbitt | metauniverse daily must read: the group image of Chinese Internet enterprises pouring into metauniverse: "there are only various survival desires, and there is no ambition for forward-lookin
- Project GFS data download
- Lesson 12 study notes 2022.02.11
猜你喜欢

You deserve this high-value open-source third-party Netease cloud music player

leetcode841. Keys and rooms (medium)

杰理之开发板上电开机,就可以手机打开 NRF 的 APP【篇】

SSM学习

Uncaught typeerror: cannot red properties of undefined (reading 'beforeeach') solution

Cookie Technology & session Technology & ServletContext object

Babbitt | metauniverse daily must read: the group image of Chinese Internet enterprises pouring into metauniverse: "there are only various survival desires, and there is no ambition for forward-lookin

NiO programming introduction

杰理之蓝牙设备想要发送数据给手机,需要手机先打开 notify 通道【篇】

Oracle column to row -- a field is converted to multiple rows according to the specified separator
随机推荐
C - Inheritance - polymorphism - virtual function member (lower)
变量的命名规则十二条
The way to learn go (II) basic types, variables and constants
Chrome view page FPS
Crawling exercise: Notice of crawling Henan Agricultural University
Win10 64 bit Mitsubishi PLC software appears oleaut32 DLL access denied
#systemverilog# 可综合模型的结构总结
Structure summary of SystemVerilog integrable model
word中如何删除某符号前面或后面所有的文字
TypeScript 变量作用域
qt颜色与字符串、uint相互转换
Wechat brain competition answer applet_ Support the flow main belt with the latest question bank file
MVVM of WPF
杰理之如若需要大包发送,需要手机端修改 MTU【篇】
[online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code
Go learning -- implementing generics based on reflection and empty interfaces
Cookie技术&Session技术&ServletContext对象
Configure raspberry pie access network
Lesson 12 study notes 2022.02.11
1091: two or three things in childhood (multi instance test)