In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article is about how the es6 array deletes specified elements. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
The es6 array deletes the specified elements: 1. Use the "arr.splice (arr.findIndex (item= > item.id===id), 1)" statement; 2, use the "arr=arr.filter ((num,index) = > {return indexation indexation reduction Val})" statement.
The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.
The first splice (index,num)
Index represents the subscript position of the array elements, and num represents the number of deletions
Arr.splice (arr.findIndex (item = > item.id = id), 1) / item is only the parameter can be written as I or v. / / the frontal id after / / is the id of the array and cannot be written casually. If you write id in the array, write id here. If num is written in the array, then write num here. / / = the id is the id number of the element you want to delete. If you write num in your array, then here is the num number, and / / 1 means you want to delete 1 element.
FindIndex (); is the location where the subscript of an element is found
As shown in the figure, there are three elements in this array. Now if we want to delete the element whose id is 24, that's what our code should say.
Arr.splice (arr.findIndex (item = > item.id = = 24), 1)
Print and find that the element with an id of 24 is deleted!
The second arr.filter ()
The filter () method creates a new array, and the elements in the new array are checked for all eligible elements in the specified array.
Note: filter () does not detect empty arrays.
Note: filter () does not change the original array.
Array.filter (function (currentValue,index,arr), thisValue)
/ / this deletes arr = arr.filter ((num,index) = > {return index! = = val}) Thank you for reading! This is the end of this article on "how to delete specified elements in the es6 array". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!
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.