当前位置:网站首页>Object value taking method in JS And []
Object value taking method in JS And []
2022-06-12 12:32:00 【I'm Mr.C】
JS Use . And Use [] The difference between values
JS There are two ways to get values for objects in —— Namely Use . And use []
Generally speaking , Object values are obtained by using .
How to write it :
let obj={
name:" nickname ",
value:" value ",
}
console.log(obj.name);// Output nickname
console.log(obj.value);// Output value
Use . It is common to take values in the form of , But you can't use string variables or numbers for attribute names
Like this :
// Wrong writing
obj.'name';
obj.10;
// This way of writing is wrong
// The best way to meet this requirement is to use [] To get the object value
Use [] Writing :
let obj={
name:"namename",
value:"content",
10:"ten",
}
console.log(obj[10]);// Output ten
console.log(obj['name']);// Output namename
It is [] The writing characteristics of , We can use for Loop to get a single object value
let arr=['name','value'];
let obj={
name:"111",
value:"222"
}
for(let i=0;i<=arr.length-1;i++){
console.log(obj[arr[i]]);
}
// Output 111
// 222
边栏推荐
- Time series database - incluxdb2 docker installation
- Bank layout meta universe: digital collections, digital employees become the main track!
- 元宇宙是短炒,还是未来趋势?
- 宏编译 预处理头 WIN32_LEAN_AND_MEAN
- Advanced chapter of C language -- ten thousand words explanation pointer and qsort function
- 【Leetcode】416. Split equal sum subset
- 你不会只会用console.log()吧?
- JS pre parsing, object, new keyword
- 【VIM】.vimrc配置,已经安装Vundle,YoucompleteMe
- C语言进阶篇——深度解剖数据在内存中的存储(配练习)
猜你喜欢

InfluxDB2.x 基准测试工具 - influxdb-comparisons

C语言深度解剖篇——关键字&&补充内容

Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference

golang的channel和条件变量在单生产单消费场景下的性能对比测试

Examples of Cartesian product and natural connection of relational algebra

大学生请假理由

安装canvas遇到的问题和运行项目遇到的报错

Bat interview & advanced, get interview materials at the end of the text

Redis的主从复制原理

JS how to convert a string into an array object
随机推荐
[转]placement new
imx6-uboot添加lvds1显示
【Leetcode】221. Largest Square
Visio 2019 uses PJ
【VIM】.vimrc配置,已经安装Vundle,YoucompleteMe
Boot entry directory
Get all IPv4 and IPv6 addresses of this computer
DOM+JS+轮播图+无时间
C语言进阶篇——深度解剖数据在内存中的存储(配练习)
Click to generate 4-bit random number and verify code setting
Numpy数值计算基础
Rust语言学习
What is modularity? Benefits of modularity
Numpy numerical calculation basis
Cocktail sort
vant 标签栏+上拉加载+下拉刷新demo van-tabs+van-pull-refresh+van-list demo
Tron API wave field transfer query interface PHP version package based on thinkphp5 attached interface document 20220528 version
MySQL 分区表介绍与测试
LDAP和SSO集成能实现什么效果?
Examples of Cartesian product and natural connection of relational algebra