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