

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to compare arrays in JavaScript?
To compare arrays in JavaScript, try to run the following code. The matched elements from both the arrays get displayed here:
Example
<html> <body> <script> var arr1 = [50,60,65,90]; var arr2 = [25,35,50,90]; for (i = 0; i < arr1.length; i++) { for (z = 0; z < arr1.length; z++) { if (arr1[i] === arr2[z]) { document.write("<br>Matched element: "+arr2[z]); } } } </script> </body> </html>
Output
Matched element: 50 Matched element: 90
- Related Questions & Answers
- Compare and fill arrays - JavaScript
- Compare arrays using Array.prototype.every() in JavaScript
- How to compare arrays in Java
- How to compare two arrays in C#?
- How to compare two arrays in Java?
- How to compare two arrays when the key is a string - JavaScript
- How to compare two arrays to see how many same elements they have in JavaScript?
- How do we compare two arrays in Java?
- Compare Two Java long Arrays
- Compare Two Java double arrays
- How to compare dates in JavaScript?
- How to compare two arrays in JavaScript and make a new one of true and false? JavaScript
- Java Program to compare two Byte Arrays
- Java Program to compare two Boolean Arrays
- How to compare two string arrays, case insensitive and independent about ordering JavaScript, ES6
Advertisements