 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
Palindrome array - JavaScript
We are required to write a JavaScript function that takes in an array of literals and checks if elements are the same or not if read from front or back i.e. palindrome.
Example
Let’s write the code for this function −
const arr = [1, 5, 7, 4, 15, 4, 7, 5, 1]; const isPalindrome = arr => {    const { length: l } = arr;    const mid = Math.floor(l / 2);    for(let i = 0; i <= mid; i++){       if(arr[i] !== arr[l-i-1]){          return false;       };    };    return true; }; console.log(isPalindrome(arr));  Output
The output in the console: −
true
Advertisements
 