当前位置:网站首页>JS some small problems about adding and accessing values to arrays
JS some small problems about adding and accessing values to arrays
2022-06-25 18:36:00 【ookaoooo】
Some small problems about adding and accessing values to arrays
Today, let's take a look at some small problems about arrays , It may help you a little , Of course, if I say something wrong, I'm also welcome to give advice , After all, I am also a rookie .
arr["bbb"]="nor 1";
arr[-2]="nor 2";
console.log(arr); >> [1, 2, 3, bbb: "nor 1", -2: "nor 2"]
console.log(arr.bbb) >> "nor 1"</pre>If we want to add a value to the array , With [] In the form of , If you write a negative number or a string, it adds... To the end of the array , And it is added in the form of key value pairs , So the next time you access this value, you can access it in the form of points , But if it is a number, it must pass [] visit .
arr["bbb"]="nor 1";
console.log(arr); [1, 2, 3, bbb: "nor 1"]
console.log(arr[3]) undefined</pre>If you add a value to an array through a string or a negative number , The next time you access it, you must also access it in the form of key value pairs
arr["bbb"]="nor 1";
arr[-2]=222;
arr.push(4);
console.log(arr); >> [1, 2, 3, 4, bbb: "nor 1"]
console.log(arr.length); >> 4</pre>It is worth noting that values added by strings or negative numbers , That array will not add its length , And those added in this way will always be at the end of the array , Because we use push Method to add a number 4 We found that it didn't add "is" to the end , Everybody knows push Method to add a value to the end of the array . Maybe we can draw a conclusion that is numbers and their arrangement , Key value pairs and key value pairs are arranged .
Update array small problem .
num.push(4,3,5); >> The return value is the last number added, that is, the number 5
num.reverse(); >> Array in reverse order , Not by size , It's the other way around
console.log(num) >>[5, 3, 4]</pre>num[5,"a",0]="111"; >>["111"] If the end says 0 Or array length plus 1 Well, as usual .
console.log(num);</pre>num[5,"a",6]="111";
console.log(num); >>[6: "111"]</pre>The back covers the front , The index written to the last bit cannot be greater than the length of the array +1, Otherwise, whether you write numbers or not, they are added through key value pairs , If it's negative, it's the same .
a[10] = 10;
console.log(a); >>[10: 10]
console.log(a.length); >>11
console.log(a[0]); >>undefined
console.log(a[10]); >>10</pre>If the length of the array is 0 Or not as long as the index you want to add , that js All previous values will be set to undefined, And it is added in the form of key value pairs .
边栏推荐
- GNU nano
- Current situation and trend analysis of China's glass packaging containers in 2021: the revenue of glass packaging containers increases year by year [figure]
- Redis6
- 07 local method stack
- Dell r530 built in hot spare status change description
- Skills to master in advanced development
- Analysis of China's medical device industry development environment (PEST) in 2021: the awareness of medical care is enhanced, and the demand for medical device products is also rising [figure]
- 网络安全检测与防范 练习题(三)
- Some recursive and iterative problem solving ideas of binary tree (clear and easy to understand)
- 焕新出发,利尔智达天下
猜你喜欢

使用宝塔来进行MQTT服务器搭建

利尔达蓝牙空调接收器方案助力打造更舒适的公路生活

JVM problem replication
![[in depth understanding of tcapulusdb technology] tcapulusdb model](/img/10/f94a5e1ebeaa803c754dd77351950f.png)
[in depth understanding of tcapulusdb technology] tcapulusdb model
![Analysis of China's road freight volume, market scale and competition pattern in 2020 [figure]](/img/93/fd2cfa315c2f6d232078f7b20a7eb1.jpg)
Analysis of China's road freight volume, market scale and competition pattern in 2020 [figure]

【深入理解TcaplusDB技术】单据受理之建表审批

anaconda下载清华源
![Overview and trend analysis of China's CT examination equipment industry in 2021 [figure]](/img/e0/d4ed9a9d91534be0d956414f6abaaa.jpg)
Overview and trend analysis of China's CT examination equipment industry in 2021 [figure]
![[in depth understanding of tcapulusdb technology] how to realize single machine installation of tmonitor](/img/aa/3ea807aa0c8ea186f2b3449055d689.png)
[in depth understanding of tcapulusdb technology] how to realize single machine installation of tmonitor

Command records of common data types for redis cli operations
随机推荐
Use pagoda to set up mqtt server
【ELT.ZIP】OpenHarmony啃论文俱乐部—见证文件压缩系统EROFS
正则表达式总结
Training of long and difficult sentences in postgraduate entrance examination day91
Analysis of China's road freight volume, market scale and competition pattern in 2020 [figure]
【深入理解TcaplusDB技术】单据受理之创建业务指南
Detailed explanation of route add command
Svn introduction and Usage Summary
【深入理解TcaplusDB技术】TcaplusDB机型
TCP/IP 测试题(二)
GNU nano
[in depth understanding of tcapulusdb technology] how to realize single machine installation of tmonitor
English name of each stage of software version
一晚上做了一个xpath终结者:xpath-helper-plus
Training of long and difficult sentences in postgraduate entrance examination day92
【深入理解TcaplusDB技术】Tmonitor后台一键安装
Development status of China's hydrotalcite industry in 2020 and analysis of major enterprises: the market scale is rapidly increasing, and there is a large space for domestic substitution [figure]
Oriental Wealth function (the most complete edition of Childe Yong)
solidity 合约地址转钱包、钱包地址转合约
LeetCode 3. Longest substring without repeated characters & sliding window