In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article introduces the knowledge of "how to remove specific numbers from es6 arrays". Many people will encounter this dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
Es6 array to remove a specific number of methods: 1, use indexOf () function to get a specific number of the index (index), syntax "array object .indexOf (numerical)"; 2, use splice () function to delete elements based on the index value obtained, syntax "array object .splice (index, 1)".
The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.
The method of removing specific numbers from es6 Array
Step 1. Use indexOf () to get the index of a specific number
The indexOf () method returns a specified element position in the array.
This method retrieves the array from beginning to end to see if it contains the corresponding element. The retrieval starts at the array start or at the beginning of the array (when no start parameter is specified). If an item is found, the location where the item first appeared is returned. The index of the start position is 0.
Returns-1 if the specified element is not found in the array.
Example: find the "39" element in the array
Var arr = [31 arr.indexOf 33 arr.indexOf 35; console.log (index)]; / / find the "39" element in the array
Step 2. Use splice (index,1) to delete the element based on the index value obtained
Index represents the subscript position of the array element, and 1 represents the deleted element.
Var arr = [31meme33, 33rect, 35pr, 31pr, 39g, 41g, 43e, 45th, 47th, 49th, 51st, 51st]; console.log (arr); / / find the "39" element in the array var index = arr.indexOf (39); console.log ("Index of the specified element:" + index); / / Delete the element arr.splice (index, 1); console.log (arr).
This is the end of "how to remove specific numbers from es6 arrays". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.