当前位置:网站首页>JS API summary of Array Operations
JS API summary of Array Operations
2022-07-26 16:21:00 【Sunny all the way ~ responsible man】
One 、 Do not change the method of the original array
concat(): Connect Array , Return a new array .- slice(): Intercept array , Index based session , Left closed right away .
- split(): Split a string into strings Array . Such as : ‘a&b&c’.split("&") ==> [a,b,c]
join(): Connect the elements in the array with a symbol . Such as :[a,b,c].join("-") ==> “a-b-c”toString(): Directly convert the array to string format , Comma separated . The effect is the same arr.join(",")ES6 Deconstruction in: newArr=[…a,…b], Sure Connect Several arrays , The original array does not change .
Two 、 Change the method of the original array
The new result of the original array after these methods , That is, the original array itself .
push(): At the end of the array Additional An element , Return array length .pop(): Delete an element at the end of the array , Returns the removed element .length Append at the end: At the end of the array Additional Another way of element , namely arr[arr.length], Return the added element .unshift(): Add an element to the head of the array , Return the added element .shift(): Delete an element in the array header , Returns the deleted element .- splice(): Used to add... At the specified location 、 Delete 、 Replacement elements .
(1)Delete arr.splice(index,len): From the index index It's about ( Include index, This method includes index In itself , I will not repeat it later ), The deletion length is len Elements , Returns the composition of deleted elements Array . If I only wrote index, There is no second parameter , From index After the beginning of deletion all Elements .
(2)add to arr.splice(index,0,...items): from index Add several elements at , return [ ] An empty array .( It can be understood that the replaced element is empty )arr.splice(arr.length,0,…[1,2,3]): Connect Array , Append an array at the end [1,2,3] Give the original array .
(3)Replace arr.splice(index,len,...items): From the index index Start , Replace len Elements , use items To replace . if len There are more elements to replace , Then all the remaining ones will be deleted . Returns the composition of the replaced element Array . sort(): Sorting method , In ascending order of strings . In the right order ( Ascending ): arr.sort((a,b)=>a-b), When a-b When a negative value is returned , The function takes a The order is ratio 100 Smaller values . Such as 10-20= -10reverse(): Inversion array , Reverse the original order , Returns the changed new array .Array.prototype.push.apply(arr1,arr2): On the prototype Connect Array , take arr2 Connected to the arr1 Tail of , The parameter can only be 2 individual , Too many invalid . Return array length ,arr1 Be changed ,arr2 unchanged . arr1.push.apply(arr1,arr2) The effect is the same .
Continuous document maintenance , If there is something wrong , I hope you can correct or add .
边栏推荐
- TDengine 落地协鑫能科,数百亿数据压缩至 600GB
- First knowledge of OpenGL (3) fragment shader
- Taishan Office Technology Lecture: the zoom ratio of word is slightly different from the display
- Delta controller rmc200
- Operating system migration practice: deploying MySQL database on openeuler
- RE9: read the paper deal inductive link prediction for nodes having only attribute information
- Bucher gear pump qx81-400r301
- Clojure Web Development -- ring user guide
- Bugku login2
- C # set different text watermarks for each page of word
猜你喜欢
![[BJDCTF2020]Easy MD5](/img/6a/61a4b5624c33f1f334bea344cfa2c8.png)
[BJDCTF2020]Easy MD5

Bugku login2

Pandora IOT development board learning (RT thread) - Experiment 17 esp8266 experiment (learning notes)

2022 latest Beijing Construction Safety Officer simulation question bank and answers

Question collection come and ask nllb authors! (Zhiyuan live issue 24)

We were tossed all night by a Kong performance bug

Re9:读论文 DEAL Inductive Link Prediction for Nodes Having Only Attribute Information

综合设计一个OPPE主页--导航栏的设计

2022牛客暑期多校训练营1(ACDGIJ)

Research and application of the whole configuration of large humanoid robot
随机推荐
The process and harvest of developing browser plug-ins with clojurescript
使用 ClojureScript 开发浏览器插件的过程与收获
PAT甲级 1049 Counting Ones
[BJDCTF2020]Easy MD5
Some cutting-edge research work sharing of SAP ABAP NetWeaver containerization
Understanding weight sharing in convolutional neural networks
绘制漂亮的中学操场轮廓,生成带经纬度数据
Google Earth Engine——MERRA-2 M2T1NXSLV:1980-至今全球压力、温度、风等数据集
2022年最新北京建筑安全员模拟题库及答案
[ten thousand words long text] Based on LSM tree thought Net 6.0 C # realize kV database (case version)
Google Earth engine - merra-2 m2t1nxlv: 1980 present global pressure, temperature, wind and other data sets
《硅谷之谜》读后感
Sword finger offer special assault edition day 11
Pat grade a 1044 shopping in Mars
想让照片中的云飘起来?视频编辑服务一键动效3步就能实现
Interface test for quick start of JMeter
Clojure Web 开发-- Ring 使用指南
一款可视化浏览器历史的 Firefox/Chrome 插件
6种方法帮你搞定SimpleDateFormat类不是线程安全的问题
The difference between oncreate and onrestoreinstancestate recovery data of activity