[removed] How to reverse a number?

前端 未结 10 919
余生分开走
余生分开走 2020-11-29 11:54

Below is my source code to reverse (as in mirror) the given number. I need to reverse the number using reverse method of arrays.

var a = prompt(\"Enter a va         


        
10条回答
  •  遥遥无期
    2020-11-29 12:06

    Explanation

    Using the JavaScript reverse() array method you can reverse the order of the array elements.

    Code

    var a = prompt("Enter a value");
    var arr = [];
    
    for (var i = 0; i < a.length; i++) {
        arr[i] = a.charAt(i);
    }
    arr.reverse();
    alert(arr);

提交回复
热议问题