
- 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
Equality of corresponding elements in JavaScript
We are required to write a JavaScript function that takes in two arrays of literals. The function should check the corresponding elements of the array. The function should return true if all the corresponding elements of the array are equal otherwise it should return false.
Example
The code for this will be −
const arr1 = [6, 7, 8, 9, 10, 11, 12, 14]; const arr2 = [6, 7, 8, 9, 10, 11, 12, 14]; 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
The output in the console −
True
- Related Articles
- Compare array elements to equality - JavaScript
- Checking the equality of array elements (sequence dependent) in JavaScript
- Strict equality vs Loose equality in JavaScript.
- Explain equality of objects in JavaScript.
- loose equality in JavaScript
- Equality of two arrays JavaScript
- object.is() in equality comparison JavaScript
- Constructing an array of smaller elements than the corresponding elements based on input array in JavaScript
- Getting elements of an array depending on corresponding values of another JavaScript
- Equality of two 2-D arrays - JavaScript
- Append the current array with the squares of corresponding elements of the array in JavaScript
- Program to test the equality of two arrays - JavaScript
- Absolute difference of corresponding digits in JavaScript
- 8086 program to determine product of corresponding elements of two array elements
- Comparing corresponding values of two arrays in JavaScript

Advertisements