Reverse decimal digits in javascript

后端 未结 14 937
灰色年华
灰色年华 2021-02-05 16:24

How do I reverse the digits of a number using bitwise?

input:

x = 123; 

output:

x = 321; 
相关标签:
14条回答
  • 2021-02-05 17:17

    you also use this function

    function myfunction(a){
       var x=a.toString();
       var y= x.split("");
       var z=y.reverse();
       var result=z.join("");
         return result;
    

    } myfunction(123);

    0 讨论(0)
  • 2021-02-05 17:18

    The code block below should do the trick

    <script type = "text/javascript">
    
    var input;
    
    input=window.prompt ("Please enter a number to be reversed.");
    x=input.length;
    
    while(x > 0)
    {
    
    x=x-1;
    document.write(input[x]);
    
    }
    
    </script>
    
    0 讨论(0)
提交回复
热议问题