当前位置:网站首页>Methods for JS object to obtain attributes (. And [] methods)
Methods for JS object to obtain attributes (. And [] methods)
2022-07-06 07:21:00 【Elephants and ants】
js There are two ways to get properties of objects :1. adopt . The way 2. adopt [] The way
// adopt . Method to get the property value ,key Is static
var aa = {
name: "zhang", age: 18};
console.log(aa.name);
// adopt [] Get attribute value , key Is dynamic , Can be a string , Or in the form of numbers
var bb = {
"apple": 3, "pear": 2}
var cc = {
1: "number1", 2: "number2"}
console.log(bb["apple"]);
console.log(cc[1]); // Note that the writing here is easily confused with array ,cc Still object , Is not an array
// Get all objects key Methods
console.log(Object.keys(bb)); // Output [ 'apple', 'pear' ]
边栏推荐
- Fundamentals of C language 9: Functions
- MPLS experiment
- Wechat official account infinite callback authorization system source code, launched in the whole network
- Get/post/put/patch/delete meaning
- leetcode841. 钥匙和房间(中等)
- navicat如何导入MySQL脚本
- The first Baidu push plug-in of dream weaving fully automatic collection Optimization SEO collection module
- Ble of Jerry [chapter]
- 杰理之如若需要大包发送,需要手机端修改 MTU【篇】
- [JDBC] quick start tutorial
猜你喜欢
【mysql学习笔记30】锁(非教程)
Idea console color log
升级版手机检测微信工具小程序源码-支持多种流量主模式
leetcode841. Keys and rooms (medium)
First knowledge of OpenGL es learning (1)
Configure raspberry pie access network
Multi attribute object detection on rare aircraft data sets: experimental process using yolov5
杰理之BLE【篇】
The author is dead? AI is conquering mankind with art
SSM学习
随机推荐
升级版手机检测微信工具小程序源码-支持多种流量主模式
How Navicat imports MySQL scripts
Memory error during variable parameter overload
配置树莓派接入网络
leetcode1020. Number of enclaves (medium)
navicat如何导入MySQL脚本
【线上问题处理】因代码造成mysql表死锁的问题,如何杀掉对应的进程
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
Supervisor usage document
TS基础篇
[MySQL learning notes 32] mvcc
ORACLE列转行--某字段按指定分隔符转多行
杰理之BLE【篇】
TypeScript 接口属性
How can word delete English only and keep Chinese or delete Chinese and keep English
OpenJudge NOI 2.1 1749:数字方格
The way to learn go (I) the basic introduction of go to the first HelloWorld
【JDBC】快速入门教程
Go learning -- implementing generics based on reflection and empty interfaces
Multi attribute object detection on rare aircraft data sets: experimental process using yolov5