I've done some research and can't seem to find a way to do this. I even tried using a for loop to loop through the string and tried using the functions isLetter()
and charAt(
).
I have a string which is a street address for example:
var streetAddr = "45 Church St";
I need a way to loop through the string and find the first alphabetical letter in that string. I need to use that character somewhere else after this. For the above example I would need the function to return a value of C. What would be a nice way to do this?
Maybe one of the shortest solutions:
'45 Church St'.match(/[a-zA-Z]/).pop();
Since match
will return null
if there are no alphanumerical characters in a string, you may transform it to the following fool proof solution:
('45 Church St'.match(/[a-zA-Z]/) || []).pop();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With