当前位置:网站首页>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 .
边栏推荐
- The "nuclear bomb level" log4j vulnerability is still widespread and has a continuing impact
- The solution to the display disorder of several events files in the tensorboard
- 修改mysql数据库root用户的密码
- Summary of key knowledge of C language
- 技术风向标 | 云原生技术架构成熟度模型解读
- Re8:读论文 Hier-SPCNet: A Legal Statute Hierarchy-based Heterogeneous Network for Computing Legal Case
- Parker solenoid valve d1vw020dnypz5
- 绘制漂亮的中学操场轮廓,生成带经纬度数据
- 终于有人把红蓝对抗讲明白了
- 使用 ClojureScript 开发浏览器插件的过程与收获
猜你喜欢

Test cases should never be used casually, recording the thinking caused by the exception of a test case

PAT甲级 1049 Counting Ones

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

Advanced CAD exercises (I)

Re8:读论文 Hier-SPCNet: A Legal Statute Hierarchy-based Heterogeneous Network for Computing Legal Case

【物理模拟】最简单的shape matching的原理与实践
最终一致性性分布式事务 TCC

Pat grade a 1049 counting ones

Google Earth Engine——MERRA-2 M2T1NXAER:1980-2022年气溶胶逐日数据集

提问征集丨快来向NLLB作者提问啦!(智源Live第24期)
随机推荐
DTS搭载全新自研内核,突破两地三中心架构的关键技术|腾讯云数据库
[BJDCTF2020]Easy MD5
Activity之onCreate、onRestoreInstanceState恢复数据的区别
Compiler analysis of clojure operation principle
Delta controller rmc200
Clojure Web Development -- ring user guide
Development daily summary (11): file upload function improvement: Chinese character detection and text content processing
13 years of senior developers share a year of learning rust experience: from the necessary bibliography to code practice
综合设计一个OPPE主页--顶部,头部的设计
2022 test questions and answers for the latest national fire facility operator (senior fire facility operator)
Is it safe for Guoyuan futures to open an account online? What is the account opening process?
TKE集群节点max-pod是如何配置的
该怎么写单元测试呢
PAT甲级 1045 Favorite Color Stripe
JVM 的类初始化机制
The process and harvest of developing browser plug-ins with clojurescript
Sql语句——单行注释与多行注释
综合设计一个OPPE主页--布局与初始化
2022 latest Beijing Construction Safety Officer simulation question bank and answers
【E-MR】NameNode的错误恢复记录