当前位置:网站首页>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' ]
边栏推荐
- Bugku CTF daily question: do you want seeds? Blackmailed
- #systemverilog# 可綜合模型的結構總結
- Crawling exercise: Notice of crawling Henan Agricultural University
- 杰理之BLE【篇】
- [some special grammars about C]
- word中把帶有某個符號的行全部選中,更改為標題
- Oracle column to row -- a field is converted to multiple rows according to the specified separator
- UWA pipeline version 2.2.1 update instructions
- 位运算异或
- How MySQL merges data
猜你喜欢

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

How are the open source Netease cloud music API projects implemented?

Twelve rules for naming variables

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

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

Excel的相关操作

Setting and using richview trvstyle template style

Interface automation test framework: pytest+allure+excel

How Navicat imports MySQL scripts

Multi attribute object detection on rare aircraft data sets: experimental process using yolov5
随机推荐
微信脑力比拼答题小程序_支持流量主带最新题库文件
多线程和并发编程(二)
Chrome view page FPS
JDBC学习笔记
Applied stochastic process 01: basic concepts of stochastic process
作者已死?AI正用藝術征服人類
Introduction to the basics of network security
OpenJudge NOI 2.1 1661:Bomb Game
TypeScript 接口属性
First knowledge of OpenGL es learning (1)
剪映的相关介绍
Twelve rules for naming variables
Cif10 actual combat (resnet18)
ORACLE列转行--某字段按指定分隔符转多行
OpenGL ES 学习初识(1)
Internal and external troubles of "boring ape" bayc
TS基础篇
win10 64位装三菱PLC软件出现oleaut32.dll拒绝访问
leetcode1020. 飞地的数量(中等)
MPLS experiment