当前位置:网站首页>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 .
边栏推荐
- 【深入理解TcaplusDB技术】集群管理操作
- 网络安全检测与防范 测试题(二)
- el-table高度自适应
- Command records of common data types for redis cli operations
- RMAN备份数据库_重启RMAN备份
- Use pagoda to set up mqtt server
- Training of long and difficult sentences in postgraduate entrance examination day92
- Move graph explorer to jupyterab: use ges4jupyter to connect ges and explore graphs
- Kwai 616 war report was launched, and the essence was thrown away for the second time to lead the new wave. Fast brand jumped to the top 3 of the hot list
- Overview and trend analysis of China's foreign direct investment industry in 2020 [figure]
猜你喜欢
[deeply understand tcapulusdb technology] create a game area for document acceptance
[in depth understanding of tcapulusdb technology] tcapulusdb operation and maintenance
Redis 5.0 data structure double end linked list source code analysis
利尔达蓝牙空调接收器方案助力打造更舒适的公路生活
Differences and relations between sequential table and array (easy to confuse), linear table and linked list
【深入理解TcaplusDB技术】单据受理之事务执行
[deeply understand tcapulusdb technology] transaction execution of document acceptance
[in depth understanding of tcapulusdb technology] new models of tcapulusdb
Regular expression summary
[in depth understanding of tcapulusdb technology] tcapulusdb model
随机推荐
中金财富安全吗? 开户需要多久
PHP数据库连接version1.1
JVM|运行时数据区(堆空间)
[deeply understand tcapulusdb technology] tmonitor system upgrade
[in depth understanding of tcapulusdb technology] tcapulusdb operation and maintenance
【深入理解TcaplusDB技术】单据受理之创建业务指南
Class 02 loader subsystem
158_ Model_ Power Bi uses DAX + SVG to open up almost all possibilities for making business charts
[in depth understanding of tcapulusdb technology] new models of tcapulusdb
C#泛型类案例
《痞子衡嵌入式半月刊》 第 57 期
华为云SRE确定性运维专刊(第一期)
Training of long and difficult sentences in postgraduate entrance examination day91
RMAN backup database_ Restart RMAN backup
LeetCode-78-子集
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]
Web development solution to cross domain problems
Analysis on development scale and development trend of China's night economy industry in 2021 [figure]
RMAN备份数据库_目录
In 2021, China's private equity market is growing, and the scale of private equity fund management reaches 19.78 trillion yuan [figure]