This article example shares the specific code for JavaScript to implement array filtering for your reference. The specific content is as follows Today, I used my knowledge of JavaScript to create an example of filtering an array. I hope we can learn from each other and make progress together! Final result: js code part: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Filter Array</title> <script> function Search(arr) { var newArr = []; for (var i = 0; i < arr.length; i++) { if (arr[i] > 10) { newArr[newArr.length] = arr[i]; } } return newArr; } var arr = [1, 2, 45, 31, 7, 30, 22, 3, 5, 17]; Search(arr); alert('The numbers you entered are '+arr+'\n'+'The numbers greater than 10 are: '+Search(arr)); </script> </head> <body> </body> </html> summary: Filtering arrays is very common and important in various programming languages. I hope everyone can use it skillfully. I saw a piece of code before: js filters the object array according to the array, share it with you According to the array storing the id, filter the object with this id var array = [ { time: '2020', id: '1', }, { time: '2020', id: '2', }, { time: '2020', id: '3', }]; var filterIds = ['1', '3']; var result = array.filter((a,i)=>{ return filterIds.some(f=>(f === a.id)) }) //[{time: "2020", id: "1"},{time: "2020", id: "3"} The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Tutorial on installing MySQL 5.6 using RPM in CentOS
>>: Detailed steps to install Anaconda on Linux (Ubuntu 18.04)
Enter Alibaba vector icon library Alibaba Vector ...
Use native js to implement a simple calculator (w...
Preface Interceptor In some modern front-end fram...
If people have been idle for too long, they will ...
Table of contents Preface Step 1: Setup and front...
What is Vite? (It’s a new toy on the front end) V...
Table of contents Table definition auto-increment...
I have just come into contact with and become fam...
This is a cheating scheme for voting websites wit...
Syntax composition: 1 Annotation information 2 Co...
This article records the installation and configu...
Environmental preparation: VMware+CentOS, jdk 1. ...
A vector wave <svg viewBox="0 0 560 20&qu...
When is the table used? Nowadays, tables are gene...
Table of contents 1. Effect display 2. Enhanced v...