VOOZH about

URL: https://www.geeksforgeeks.org/javascript/javascript-program-to-display-armstrong-numbers-between-1-to-1000/

⇱ JavaScript Program to Display Armstrong Numbers Between 1 to 1000 - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

JavaScript Program to Display Armstrong Numbers Between 1 to 1000

Last Updated : 19 Feb, 2024

Armstrong number is a number equal to the sum of its digits raised to the power 3 of the number of digits. For example, 153 is an Armstrong number because 1^3 + 5^3 + 3^3 = 153. This article will explore how to find Armstrong numbers between 1 to 1000 using JavaScript.

Approach 1: Display Armstrong Numbers Between 1 to 1000 using a Loop

The simplest approach to finding Armstrong numbers is using a loop to iterate through each number from 1 to 1000 and check if it is an Armstrong number.


Output
1
2
3
4
5
6
7
8
9
153
370
371
407

Approach 2: Display Armstrong Numbers Between 1 to 1000 using Array Methods

We can also use JavaScript array methods to make the code more concise and functional. In this approach, we convert the number to a string, split it into an array of digits, and then use the reduce method to calculate the sum of each digit raised to the power of the number of digits.


Output
1
2
3
4
5
6
7
8
9
153
370
371
407
Comment