JavaScript Filter Array Multiple Values
Last Updated : Mar 11, 2024
IN - JavaScript | Written & Updated By - Riya
In this tutorial we will show you the solution of JavaScript filter array multiple values and we will learn about how to apply filter on array having multiple values.
In last tutorial, we understand that how we are able to store and display values with the help of array using MySQL database.
Now, in this article we will understand about filtering of array. Now, let us understand this article.
Step By Step Guide On JavaScript Filter Array Multiple Values :-
As, there are many ways to apply filters on arrays having multiple values because there are many types of arrays also.
In this article, we understand filtering of arrays with basic method. In next method, we will create an array having large and complex set of values and understand them.
One thing to note here that we use here filter method to apply filter of array. Let us understand how to use filter on arrays.
<!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>home page</title> </head> <body> <script> let numbers = {3,7,15,19,23,29,31,37,43}; let filteredNumber = numbers.filter(function(currentElement) { return currentElement > 3 && currentElement <30; }); Console.log(filteredNumber); </script> </body> </html>
- First, we write <! DOCTYPE html> which we used as an instruction to the web browser about what version of HTML file is written in.
- Secondly, the <html> tag is used to indicate the beginning of an HTML document.
- As above now <head> tag is used to contain information about web page. In this tag a <title> tag is used which helps us to specify a webpage title. Both <head> and <title> tags are Paired tags. So, both have </head> and </title> ending tags respectively.
- Here, then we create a body tag. All the content which we want to show on browser’s screen or display is always written inside this codes.
- Here, inside body we create a script tag which is again a paired tag. We write our JavaScript code inside this tag.
- Here, under script tag we create a variable with name numbers and store some values inside this number.
- After this we apply filter on that number and create a condition that it will return the elements that are greater than 3 and less than 30. Our filtered number will get store in a variable having name filteredNumber.
- Now, at last we just have to print that stored numbers that are inside filteredNumber variable. To print them we use console and print them in console. You can see the printed numbers under console section.
- To open console section, you just have to inspect website by right click on page and open console to see the result.
- At last, the <body> and <html> tags are closed with </body> and </html> respectively.
Conclusion :-
At last in conclusion, here we can say that with the help of this article we are able to apply filter on arrays having multiple values using JavaScript.
I hope this tutorial on JavaScript filter array multiple values helps you and the steps and method mentioned above are easy to follow and implement.