
- 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
Finding the nth palindrome number amongst whole numbers in JavaScript
Problem
We are required to write a JavaScript function that takes in number n. Our function should return the nth palindrome number if started counting from 0.
For instance, the first palindrome will be 0, second will be 1, tenth will be 9, eleventh will be 11 as 10 is not a palindrome.
Example
Following is the code −
const num = 31; const findNthPalindrome = (num = 1) => { const isPalindrome = (num = 1) => { const reverse = +String(num) .split('') .reverse() .join(''); return reverse === num; }; let count = 0; let i = 0; while(count < num){ if(isPalindrome(i)){ count++; }; i++; }; return i - 1; }; console.log(findNthPalindrome(num));
Output
Following is the console output −
212
- Related Articles
- Finding the nth prime number in JavaScript
- Finding the nth digit of natural numbers JavaScript
- Finding nth digit of natural numbers sequence in JavaScript
- Finding the nth missing number from an array JavaScript
- Finding the nth element of the lucas number sequence in JavaScript
- Palindrome numbers in JavaScript
- Finding a number and its nth multiple in an array in JavaScript
- Finding the sum of all numbers in the nth row of an increasing triangle using JavaScript
- Finding the nth power of array element present at nth index using JavaScript
- Finding the nth day from today - JavaScript (JS Date)
- Finding nth element of the Padovan sequence using JavaScript
- Finding perfect numbers in JavaScript
- Finding tidy numbers - JavaScript
- Finding two prime numbers with a specific number gap in JavaScript
- Finding sum of every nth element of array in JavaScript

Advertisements