// Function to reverse Number
function reverseNum(n) {
let r = n.toString().split('').reverse().join('');
return Math.sign(n) * parseInt(r);
}
// Call
reverseNum(-267);
reverseNum(31522);
// Outputs
-762
22513
// how to reverse number in javascript
let number = 12345;
let reverse = parseInt(number.toString().split('').reverse().join(''));
console.log(reverse);
// Output:
// 54321
let rev = 0;
let num = 123456;
let lastDigit;
while(num != 0){
lastDigit = num % 10;
rev = rev * 10 + lastDigit;
num = Math.floor(num/10);
}
console.log("Reverse number : "+rev);
const num = 3849;
function reverseGivenInteger(num) {
return Number(String(num).split('').reverse().join(''))
}
console.log(`Reversed integer is: ${reverseGivenInteger(num)}`)
var text = ""
var i = 0
var array = ["1", "2", "3"]
var number = array.length
var arrayFinal = []
for (i = 0; i < array.length; i++) {
text = array[number - 1]
arrayFinal.push(text)
text = ""
number = number - 1
}
console.log(arrayFinal)