Most efficient way to check that string variable is a single alphanumeric character
I could do it with regex (something like myString.match(/^[A-Za-z0-9]开发者_StackOverflow$/)
) but it seems like an overkill.
What would be more effective performance-wise?
Thanks.
Use the length property and the charCodeAt( 0 ) function to check the range of the ASCII value...
Well obviously, the most efficient is an indexed lookup into an array (pre-configured with appropriate boolean results). This is a very bad approach, in general, however. (Because it's non-standard and almost certainly not neccessary).
精彩评论