1. forEach() Traverse the array without return. Even if there is return, no value will be returned and the original array will be affected. callback parameters let arr = ["a", "b", "c", 1, 2, 3]; arr.forEach((value, index, arr) => { console.log(value, index, arr); }) Output: 2. arr.filter() Filter an array and return an array that meets the requirements callback parameters: 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 meet the requirements, if so, return true callback parameters: let arr = [1,2,3,4,5] let arr1 = arr.every( (value, index) =>value<2) console.log(arr1) // false let arr2 = arr.every( (value, index) =>value<6) console.log(arr2) // true 4. arr.map() Map an array (traverse the array), and return a new array. callback parameters: let arr = [1,2,3,4,5] arr.map( (value,index,array)=>{ value = value * 2 console.log(`value:${value} index:${index} array:${array}`) }) console.log(arr) result: 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 meets the condition, if one meets the condition, return true callback parameters: let arr = [1,2,3,4,5] let arr1 = arr.some( (value, index) => value < 3) console.log(arr1) // true let arr2 = arr.some( (value, index) => value > 6) console.log(arr2) // false SummarizeThis article ends here. I hope it can be helpful to you. I also hope you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: CSS3 sets a mask for the background image and solves the problem of mask style inheritance
Preface The previous article installed Hadoop, an...
1. Virtual environment virtualenv installation 1....
Description of port availability detection when p...
Table of contents Overview The role of reverse pr...
Basic introduction to robots.txt Robots.txt is a p...
A very common scenario in react projects: const [...
This article shares the specific code of JavaScri...
Introduction: This article takes the sample proje...
Click here to return to the 123WORDPRESS.COM HTML ...
1. Basic Concepts 1. Sitemesh is a page decoratio...
Problem code Look at a closure problem code cause...
Table of contents Introduction to Arrays Array li...
Background: Make a little progress every day, acc...
This case is based on CentOS 7 system Suitable fo...
Pull the image root@EricZhou-MateBookProX: docker...