当前位置:网站首页>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' ]
边栏推荐
- [MySQL learning notes 32] mvcc
- Bit operation XOR
- 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
- (4) Web security | penetration testing | network security web site source code and related analysis
- leetcode841. 钥匙和房间(中等)
- 学go之路(一)go的基本介绍到第一个helloworld
- TypeScript void 基础类型
- 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
- 【mysql学习笔记29】触发器
- How to configure GUI guide development environment
猜你喜欢
mysql如何合并数据
杰理之BLE【篇】
Leetcode35. search the insertion position (simple, find the insertion position, different writing methods)
微信公众号无限回调授权系统源码 全网首发
【MySQL学习笔记32】mvcc
作者已死?AI正用藝術征服人類
Solution to the problem of breakthrough in OWASP juice shop shooting range
Multi attribute object detection on rare aircraft data sets: experimental process using yolov5
Excel的相关操作
idea控制台彩色日志
随机推荐
Establishment and operation of cloud platform open source project environment
The differences and advantages and disadvantages between cookies, seeion and token
How Navicat imports MySQL scripts
Uncaught typeerror: cannot red properties of undefined (reading 'beforeeach') solution
Memory error during variable parameter overload
(4) Web security | penetration testing | network security web site source code and related analysis
If Jerry's Bluetooth device wants to send data to the mobile phone, the mobile phone needs to open the notify channel first [article]
Ble of Jerry [chapter]
word中把帶有某個符號的行全部選中,更改為標題
word删除括号里内容
How to configure GUI guide development environment
微信公众号无限回调授权系统源码 全网首发
leetcode1020. Number of enclaves (medium)
NiO programming introduction
TS基础篇
TypeScript 可索引类型
When the Jericho development board is powered on, you can open the NRF app with your mobile phone [article]
Typescript interface properties
OpenJudge NOI 2.1 1749:数字方格
LeetCode Algorithm 2181. Merge nodes between zero