当前位置:网站首页>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' ]
边栏推荐
- 变量的命名规则十二条
- Jerry needs to modify the profile definition of GATT [chapter]
- Leetcode 78: subset
- Thought map of data warehouse construction
- Multi attribute object detection on rare aircraft data sets: experimental process using yolov5
- Typescript interface properties
- word中如何删除某符号前面或后面所有的文字
- 1189. Maximum number of "balloons"
- Word delete the contents in brackets
- 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
猜你喜欢

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

SSM learning
![If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]](/img/d6/92ad1c6f84415de6ab0dfd16cd6073.png)
If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]

Summary of Digital IC design written examination questions (I)
![Ble of Jerry [chapter]](/img/ed/32a5d045af8876d7b420ae9058534f.png)
Ble of Jerry [chapter]

Leetcode35. search the insertion position (simple, find the insertion position, different writing methods)

leetcode841. Keys and rooms (medium)

NiO programming introduction

Go learning --- use reflection to judge whether the value is valid

Cookie Technology & session Technology & ServletContext object
随机推荐
网络安全基础介绍
Word delete the contents in brackets
Week6 weekly report
leetcode1020. Number of enclaves (medium)
The best way to learn SEO: search engine
OpenGL ES 学习初识(1)
Excel的相关操作
[JDBC] quick start tutorial
Ble of Jerry [chapter]
Ble of Jerry [chapter]
TypeScript 接口属性
C - Inheritance - polymorphism - virtual function member (lower)
Go learning --- use reflection to judge whether the value is valid
Raspberry pie serial port login and SSH login methods
ORACLE列转行--某字段按指定分隔符转多行
TypeScript void 基础类型
杰理之开发板上电开机,就可以手机打开 NRF 的 APP【篇】
navicat如何导入MySQL脚本
杰理之普通透传测试---做数传搭配 APP 通信【篇】
supervisor 使用文档