I need assistance with a JavaScript issue where I am trying to extract the last digit from a string. Here is the code I am using:
var idval = focused.id;
var lastChar1 = idval.substr(idval.length - 1);
For example, if the id name is idval5, the code correctly returns 5.
However, when the id name is idval21, it only returns 1. I am looking for a way to get 21 as the output instead.
If anyone could provide some guidance or assistance, it would be greatly appreciated.