
- 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
Checking for special type of Arrays in 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. Such arrays are also known by the name of palindrome arrays.
Some examples of palindrome arrays are −
const arr1 = [‘a’, ‘b’, ‘c’, ‘b’, ‘a’]; const arr2 = [4, 7, 7, 4]; const arr3 = [7, 7, 7, 7, 7, 7];
Example
The code for this will be −
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
- Related Articles
- Checking for special numbers in JavaScript
- Checking for ascending arrays in JavaScript
- Checking for squared similarly of arrays in JavaScript
- Checking for centrally peaked arrays in JavaScript
- Special arrays in JavaScript
- Checking for the similarity of two 2-D arrays in JavaScript
- Special type of numbers (pronic) in JavaScript
- Special type of sorting algorithm in JavaScript
- Finding special type of numbers - JavaScript
- Special type of sort of array of numbers in JavaScript
- Checking for uniqueness of a string in JavaScript
- Checking for permutation of a palindrome in JavaScript
- Checking for particular types of matrix in JavaScript
- Checking if two arrays can form a sequence - JavaScript
- Checking for Fibonacci numbers in JavaScript

Advertisements