In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how js deletes the last element in an array". The editor shows you the operation process through an actual case. The method of operation is simple and fast, and it is practical. I hope this article "how to delete the last element of an array by js" can help you solve the problem.
1. Merge array: concat ()
Grammar
String.concat (string1, string2, … , stringX)
Example
Var arr = [1, 2, 3, 7]; arr.concat ([5, 5, 6, 7)) / / [1, 2, 3, 4, 4, 5, 6, 7] 2, adding elements at the end: push ()
Grammar
Array.push (item1, item2, … , itemX)
Example
Let a = [1JEI 2jue 3]; let item = a.push ('end'); / / 4console.log (a); / / [1JEI 2JI 3Jing']
3. Delete the last element in an array: pop ()
Grammar
Array.pop ()
Example
Var a = [1JI 2jue 3]; var b = a.pop () console.log (b) / / 3
4. Add one or more elements at the beginning: unshift ()
Grammar
Array.unshift (item1,item2, … , itemX)
Example
Let arr = [2, 3, 1, 9, 7, 5, 8, 22]; console.log (arr); arr.unshift ("new1", "new2", "new3"); console.log (arr); output: [2, 3, 1, 9, 7, 5, 8, 22] ['new1',' new2', 'new3', 2, 3, 1, 9, 7, 5, 8, 22]
5. Array sorting: sort ()
Grammar
Array.sort (sortfunction)
Example
Var a = [3, 1, 5, 5, 2]; var b = a.sort () console.log (b) / / [1, 2, 3, 4, 5]
6. Add / remove array elements: splice ()
Grammar
Array.splice (index,howmany,item1, … , itemX)
Example
Let arr = [2, 3, 1, 9, 7, 5, 8, 22]; console.log (arr); console.log (arr.splice (2,3, "this is a newly added element"); console.log (arr); output result: [2, 3, 1, 9, 7, 5, 8, 22] [1, 9, 7] [2, 3, 'this is a newly added element', 5, 8, 22]
7. Reverse the order of the elements in the array: reverse ()
Grammar
Array.reverse ()
Example
Let a = [1rem 2je 3]; a.reverse (); console.log (a); / / [3je 2jue 1] about "how js deletes the last element in an array", thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.