当前位置:网站首页>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' ]
边栏推荐
- How to configure GUI guide development environment
- 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
- leetcode35. 搜索插入位置(简单,找插入位置,不同写法)
- #systemverilog# 可综合模型的结构总结
- win10 64位装三菱PLC软件出现oleaut32.dll拒绝访问
- The psychological process from autojs to ice fox intelligent assistance
- Multi attribute object detection on rare aircraft data sets: experimental process using yolov5
- Jerry needs to modify the profile definition of GATT [chapter]
- GET/POST/PUT/PATCH/DELETE含义
- Bugku CTF daily question: do you want seeds? Blackmailed
猜你喜欢

Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案

JDBC learning notes

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

Twelve rules for naming variables

leetcode704. Binary search (find an element, simple, different writing)

Win10 64 bit Mitsubishi PLC software appears oleaut32 DLL access denied

CDN acceleration and cracking anti-theft chain function

学go之路(一)go的基本介绍到第一个helloworld

Short video, more and more boring?

SSM learning
随机推荐
【MySQL学习笔记32】mvcc
win10 64位装三菱PLC软件出现oleaut32.dll拒绝访问
Detailed explanation | detailed explanation of internal mechanism of industrial robot
leetcode1020. Number of enclaves (medium)
Short video, more and more boring?
杰理之开发板上电开机,就可以手机打开 NRF 的 APP【篇】
Project GFS data download
Uncaught TypeError: Cannot red propertites of undefined(reading ‘beforeEach‘)解决方案
学go之路(一)go的基本介绍到第一个helloworld
(4) Web security | penetration testing | network security web site source code and related analysis
How can word delete English only and keep Chinese or delete Chinese and keep English
What does UDP attack mean? UDP attack prevention measures
Memory error during variable parameter overload
Setting and using richview trvstyle template style
杰理之BLE【篇】
Supervisor usage document
【线上问题处理】因代码造成mysql表死锁的问题,如何杀掉对应的进程
The first Baidu push plug-in of dream weaving fully automatic collection Optimization SEO collection module
Establishment and operation of cloud platform open source project environment
Simple use of JWT