当前位置:网站首页>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' ]
边栏推荐
猜你喜欢

微信公众号无限回调授权系统源码 全网首发

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

What is the biggest problem that fresh e-commerce is difficult to do now

3. Business and load balancing of high architecture

Week6 weekly report

How Navicat imports MySQL scripts

MPLS experiment

SSM学习

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 first Baidu push plug-in of dream weaving fully automatic collection Optimization SEO collection module
随机推荐
ORACLE列转行--某字段按指定分隔符转多行
[online problem processing] how to kill the corresponding process when the MySQL table deadlock is caused by the code
Establishment and operation of cloud platform open source project environment
Week6 weekly report
NiO programming introduction
杰理之BLE【篇】
TypeScript 函数定义
On the world of NDK (2)
The best way to learn SEO: search engine
学go之路(一)go的基本介绍到第一个helloworld
Path analysis model
Applied stochastic process 01: basic concepts of stochastic process
#systemverilog# 可綜合模型的結構總結
LeetCode 78:子集
MPLS experiment
杰理之开发板上电开机,就可以手机打开 NRF 的 APP【篇】
Is software testing outsourcing going or not? Three years' real outsourcing experience tells you
TypeScript void 基础类型
Crawling exercise: Notice of crawling Henan Agricultural University
树莓派3B更新vim