1. IntroductionArray filter is a common method of front-end data processing. For the front-end, we need to process the data returned by the back-end before we can get the data we want and perform further operations. Sometimes the value returned to us by the backend can only be used as a reference. 2. Introduction to the MethodThe filter() method creates a new array. The data in the array is the data that meets the conditions after filtering out the specified data. Two major features of filter() 1.filter() does not detect empty arrays 2.filter() does not change the original array Usage of filter() method: array.filter(function(currentValue,index,arr), thisValue) //currentValue: the value of the current element //index: the subscript of the current element //arr: the original array 3. Usage Examples1. Get the elements in the array that meet the conditions const school = [ { occupation:"teacher", age:40 }, { occupation:"student", age:23 },{ occupation:"Programmer", age:1 } ] var newShool = school.filter(item => item.age > 20) console.log(newShool);//[ { occupation: 'Teacher', age: 40 }, { occupation: 'Student', age: 23 } ] SummarizeThis article ends here. I hope it can be helpful to you. I also hope that you can pay more attention to more content on 123WORDPRESS.COM! You may also be interested in:
|
<<: How to modify the root password of mysql in docker
>>: Various transformation effects of HTML web page switching
1. Introduction Recently I found that there are m...
This article mainly introduces CSS circular hollo...
In summary: 1. Consider performance when designin...
First, we need a server with Docker installed. (I...
Written in front No matter how well the code is w...
Table of contents Preface: 1. Create index method...
Table of contents 1. Array Induction 1. Split a s...
[LeetCode] 185. Department Top Three Salaries The...
1. What is mycat A completely open source large d...
Copy code The code is as follows: <!DOCTYPE ht...
Because I want to write a web page myself, I am al...
Importing data with incorrect MySQL character set...
Table of contents Basic Types any type Arrays Tup...
What is DOM? With JavaScript, you can reconstruct...
Introduction: When using MySQL to create a table,...