In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what are the new array methods of JavaScript es6". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian and go deeper to study and learn "what are the new array methods of JavaScript es6" together!
1. forEach()
Traversing an array, no return Even if there is a return, it does not return any value and affects the original array.
Parameters of callback
value --the value of the current index
index --index
arr --original array
let arr = ["a", "b", "c", 1, 2, 3]; arr.forEach((value, index, arr) => { console.log(value, index, arr); })
Output:
2. arr.filter()
Filter the array and return an array that meets the requirements
Parameters of callback:
value --the value of the current index
index --index
let arr = [1,2,3,4,5]let arr1 = arr.filter( (value, index) => value%2 === 0)console.log(arr1) // [2, 4]3. arr.every()
According to the judgment condition, whether all elements of the array are satisfied, if satisfied, return true
Parameters of callback:
value --the value of the current index
index --index
let arr = [1,2,3,4,5]let arr1 = arr.every( (value, index) =>valuevalue{ value = value * 2 console.log(`value:${value} index:${index} array:${array}`)}) console.log(arr)
Results:
var arr1 = [1,2,3,4]; var res1 = arr1.map((item,index,arr)=>{ item = item * 3; return item; })console.log(arr1); // [1,2,3,4]console.log(res1); // [3,6,9,12]5. arr.some()
According to the judgment condition, whether one of the elements of the array is satisfied, and if one is satisfied, return true.
Parameters of callback:
value --the value of the current index
index --index
let arr = [1,2,3,4,5]let arr1 = arr.some( (value, index) => value
< 3)console.log(arr1) // truelet arr2 = arr.some( (value, index) =>value > 6) console.log (arr2) // false Thank you for reading, the above is "JavaScript es6 new array methods what" content, after learning this article, I believe we have a deeper understanding of JavaScript es6 new array methods what this problem, the specific use of the situation also needs to be verified. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!
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.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.