当前位置:网站首页>Understanding of js arrays
Understanding of js arrays
2022-07-31 05:58:00 【messy me】
Array (Array) is an object, which is similar in function to our ordinary objects and is also used to store some values.The difference is that ordinary objects use strings as property names, while arrays use numbers as index operation elements.
Index:
The integer starting from 0 is the index. The storage performance of arrays is better than that of ordinary objects. In development, we often use arrays to store some data.
Array objects are created by adding elements:Create array object syntax:Syntax 1: var arr = new Array();Syntax 2: var arr = []; When using typeof to check an array, it will return the object type.Elements in an array can be of any data type.The elements in the array are separated by .The difference between grammar 1 and grammar 2.var arr = new Array(10); var arr = [10];Syntax 1 creates an array arr with an array length of 10, and syntax 2 creates an array with an element of 10.Add array element:
Syntax: arr[index value]=data value; such as: arr[0]=1;arr[1]=1;
Read elements in an array syntax:
Syntax: array[index].If reading an index that does not exist, it will not report an error but return undefined.
Get the length of the array:
Syntax: array.length; such as: arr.length.
Modify the length of the array
If the modified length is greater than the original length, the extra part will be vacated.
If the modified length is less than the original length, the extra elements will be deleted.
Add an element to the array
Syntax: array[array.length]=value;
2D array
When we add elements to an array as an array, the array is called a two-dimensional array.
| Method | Description | How to use |
| concat() | Concatenates two or more arrays and returns the result. | Original array name.concat(connection array name); |
| join() | Puts all elements of the array into a string.Elements are split by the specified separator. | Array name.join("Separator"); |
| pop() | Remove and return the last element of the array. | ArrayName.pop(); |
| push() | Adds one or more elements to the end of the array and returns the new length. | Array name.push("Add element"); |
| reverse() | Reverses the order of elements in the array. | ArrayName.reverse(); |
| shift() | Remove and return the first element of the array. | ArrayName.shift(); |
| slice() | Returns the selected element from an existing array. | s array name.slice(x,y); x is the starting position, y is the accommodation position. |
| sort() | Sorts the elements of the array. | ArrayName.sort(); This method sorts alphabetically and as a string. |
| splice() | Remove elements and add new elements to the array. | Array name.splice(x,y,"add element"); x is the position to add new elements, y is to delete several elements. |
| toString() | Converts the array to a string and returns the result. | ArrayName.toString(); This method returns an array as a comma-separated string |
| unshift() | Adds one or more elements to the beginning of the array and returns the new length. | Array name.unshift("Add element"); |
| valueOf() | Returns the original value of the array object. | ArrayName.valueOf(); The return result is the same as the original array. |
More other ways to view the array:
边栏推荐
- Install mysqldb in mac10.14
- sql add default constraint
- Digital twins will be an important way to enter the "metaverse"
- 2021 Mianjing - Embrace Change
- [uiautomation] Get WeChat friend list (stored in txt)
- feign调用不通问题,JSON parse error Illegal character ((CTRL-CHAR, code 31)) only regular white space (r
- [windows]--- SQL Server 2008 super detailed installation tutorial
- 自定dialog 布局没有居中解决方案
- How MySQL - depots table?A look at will understand
- What is GameFi?
猜你喜欢

flutter arr dependencies

工件SSMwar exploded 部署工件时出错。请参阅服务器日志了解详细信息

Chinese garbled solution in UTF-8 environment in Powershell

CMOS管原理,及其在推挽电路中的应用

Yuan prospect and four track of the universe

NFTs: The Heart of Digital Ownership

【JVM加载】---类加载机制

Using IIS10 to build an asp website in win11

Why does read in bash need to cooperate with while to read the contents of /dev/stdin

What is the difference between NFT and digital collection?
随机推荐
使用ps | egrep时过滤排除掉egrep自身
cocos2d-x-3.2图片灰化效果
SSH自动重连脚本
What is an EVM Compatible Chain?
Several solutions for mysql startup error The server quit without updating PID file
一文速学-玩转MySQL获取时间、格式转换各类操作方法详解
SQLite 查询表中每天插入的数量
【ubuntu20.04安装MySQL以及MySQL-workbench可视化工具】
(Crypto essential dry goods) Detailed analysis of the current NFT trading markets
configure:error no SDL library found
2021面经-拥抱变化
GUCCI、LV等奢侈品巨头如何布局元宇宙的,其他品牌应该跟上吗?
mac10.14中安装mysqldb
Markdown 帮助文档
对js的数组的理解
【云原生】原来2020.0.X版本开始的OpenFeign底层不再使用Ribbon了
flutter 混合开发 module 依赖
cocos2d-x 实现跨平台的目录遍历
mysql password modification method in Linux (pro-test available)
Several forms of Attribute Changer
https://www.w3school.com.cn/