
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
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
Advertisements