JavaScript Tutorial

Extract Second Digit of Numbers

Function to retrieve the second digit from a numeric value.

function getSecondDigit(num) {
  return Math.floor(Math.abs(num) / 10) % 10;
}
console.log(getSecondDigit(12345)); // 2