
- 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 largest 5 digit number within the input number using JavaScript
Problem
We are required to write a JavaScript function that takes in a string number of at least five digits. Our function should return the greatest sequence of five consecutive digits found within the number given.
Example
Following is the code −
const num = '123546544'; const findGreatestFiveDigit = (num = '') => { const str = num.toString(); const arr = []; for(let i = 0; i < str.length; i++){ arr.push(str.slice(i, i + 5)); }; return Math.max(...arr); }; console.log(findGreatestFiveDigit(num));
Output
54654
- Related Articles
- What is the largest 5 digit number?
- Find the sum of the largest 5 -digit number and the smallest 6 -digit number.
- Finding a number, when multiplied with input number yields input number in JavaScript
- Finding the third maximum number within an array in JavaScript
- Finding the largest prime factor of a number in JavaScript
- Finding confusing number within an array in JavaScript
- Finding the count of numbers divisible by a number within a range using JavaScript
- Find the difference between the largest 3 digit number and the smallest 6 digit number.
- Find the difference between the largest 8-digit number and the smallest 6-digit number.
- Finding the largest non-repeating number in an array in JavaScript
- Finding sequential digit numbers within a range in JavaScript
- Finding all possible prime pairs that sum upto input number using JavaScript
- Finding difference of greatest and the smallest digit in a number - JavaScript
- Finding the group with largest elements with same digit sum in JavaScript
- Find the largest 4 digit number divisible by 16.

Advertisements