当前位置:网站首页>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' ]
边栏推荐
- leetcode1020. Number of enclaves (medium)
- 剪映的相关介绍
- 可变参数重载时的内存错误
- First knowledge of OpenGL es learning (1)
- Top test sharing: if you want to change careers, you must consider these issues clearly!
- #systemverilog# 可综合模型的结构总结
- [MySQL learning notes 30] lock (non tutorial)
- How MySQL merges data
- Cookie技术&Session技术&ServletContext对象
- 树莓派3B更新vim
猜你喜欢
Uncaught typeerror: cannot red properties of undefined (reading 'beforeeach') solution
navicat如何导入MySQL脚本
Top test sharing: if you want to change careers, you must consider these issues clearly!
If Jerry needs to send a large package, he needs to modify the MTU on the mobile terminal [article]
学go之路(一)go的基本介绍到第一个helloworld
【MySQL学习笔记32】mvcc
TypeScript接口与泛型的使用
L'auteur est mort? Ai utilise l'art pour conquérir l'humanité
[MySQL learning notes 30] lock (non tutorial)
C - Inheritance - polymorphism - virtual function member (lower)
随机推荐
NFT on fingertips | evaluate ambire on G2, and have the opportunity to obtain limited edition collections
The first Baidu push plug-in of dream weaving fully automatic collection Optimization SEO collection module
Path analysis model
Ble of Jerry [chapter]
Idea console color log
How to configure GUI guide development environment
Thought map of data warehouse construction
supervisor 使用文档
作者已死?AI正用藝術征服人類
Typescript void base type
【线上问题处理】因代码造成mysql表死锁的问题,如何杀掉对应的进程
Typescript function definition
Yield method of tread
首发织梦百度推送插件全自动收录优化seo收录模块
数据仓库建设思维导图
【MySQL学习笔记32】mvcc
JDBC learning notes
【JDBC】快速入门教程
Lesson 12 study notes 2022.02.11
位运算异或