

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
Convert number to a reversed array of digits in JavaScript
<p>Given a non-negative integer, we are required to write a function that returns an array containing a list of independent digits in reverse order.</p><h2>For example:</h2><pre class="result notranslate">348597 => The correct solution should be [7,9,5,8,4,3]</pre><p>The code for this will be −</p><pre class="prettyprint notranslate">const num = 348597; const reverseArrify = num => { const numArr = String(num).split(''); const reversed = []; for(let i = numArr.length - 1; i >= 0; i--){ reversed[i] = +numArr.shift(); }; return reversed; }; console.log(reverseArrify(num));</pre><p>Following is the output on console −</p><pre class="result notranslate">[ 7, 9, 5, 8, 4, 3 ]</pre>
- Related Questions & Answers
- Convert number to reversed array of digits JavaScript
- Reversed array of digits from number using JavaScript
- Is the reversed number a prime number in JavaScript
- Difference between a number and its reversed number JavaScript
- Sorting digits of all the number of array - JavaScript
- Separating digits of a number in JavaScript
- Returning number of digits in factorial of a number in JavaScript
- Recursively adding digits of a number in JavaScript
- Prime digits sum of a number in JavaScript
- Digit sum upto a number of digits of a number in JavaScript
- Recursive product of all digits of a number - JavaScript
- Product sum difference of digits of a number in JavaScript
- Finding product of Number digits in JavaScript
- How to count digits of given number? JavaScript
- Convert array of object to array of array in JavaScript
Advertisements