As you requested, you want to find the letter, and not delete the number (the same in this example, but may differ depending on your circumstances) - if this is what you want, there is another way that you can choose:
var answer = "5A"; var match = answer.match(/[a-zA-Z]/); answer = match ? match[0] : null;
He is looking for a match in the letter, not deleting the number. If a match is found, then match[0]
will represent the first letter, otherwise match
will be null.
source share