
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Program to test the equality of two arrays - JavaScript
We are required to write a JavaScript function that takes in two arrays of literals and checks the corresponding elements of the array and it should return true if all the corresponding elements of the array are equal otherwise it should return false.
Let’s write the code for this function −
Example
Following is the code −
const arr1 = [1, 4, 5, 3, 5, 6]; const arr2 = [1, 4, 5, 2, 5, 6]; const areEqual = (first, second) => { if(first.length !== second.length){ return false; }; for(let i = 0; i < first.length; i++){ if(first[i] === second[i]){ continue; } return false; }; return true; }; console.log(areEqual(arr1, arr2));
Output
Following is the output in the console −
false
- Related Articles
- Equality of two arrays JavaScript
- Equality of two 2-D arrays - JavaScript
- How to compare two arrays for equality in Perl?
- Check two float arrays for equality in Java
- Program to find uncommon elements in two arrays - JavaScript
- Intersection of two arrays JavaScript
- Java Program to check for equality between two strings ignoring the case
- Strict equality vs Loose equality in JavaScript.
- isSubset of two arrays in JavaScript
- Finding the continuity of two arrays in JavaScript
- Java Program to Concatenate Two Arrays
- JavaScript Program for find common elements in two sorted arrays
- How to merge two arrays in JavaScript?
- How to join two arrays in JavaScript?
- How to multiply two Arrays in JavaScript?

Advertisements