Why does string.match(…)[0] throws an exception?
问题 I'm trying to pull the first occurence of a regex pattern from a string all in one statement to make my code look cleaner. This is what I want to do: var matchedString = somestring.match(/some regex/g)[0]; I would expect this to be legal but it throws an exception: Exception: somestring.match(...) is null It seems like JS is trying to index the array before match is finsihed, as the array does provide atleast one match, so I don't expect it to be null. I would like some insight in why it