You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to test "Anthony Liatsis".startsWith("Anthony "). Each of the string values were stored in variables. The "Anthony " was retrieved via a regex in my code against the text of a contenteditable div. The startsWith() result was continually false. I discovered that the trailing space in "Anthony " was UTF-8 #160 which is a non-breaking space and was not equal to an empty string.
Doing "Anthony Liatsis".startsWith("Anthony ".replace(/\s/, " ")) made it work.
The text was updated successfully, but these errors were encountered:
U+0009 Tab <TAB>
U+000B Vertical Tab <VT>
U+000C Form Feed <FF>
U+0020 Space <SP>
U+00A0 Non-breaking Space <NBSP>
U+FEFF Byte Order Mark <BOM>
Zs Any other Unicode Sep. <USP>
White space characters may occur between any two tokens and at the start or end of input. White space characters may occur within a StringLiteral, a RegularExpressionLiteral, a Template, or a TemplateSubstitutionTail where they are considered significant characters forming part of a literal value.
@rwaldron is correct on this one. The definition of startsWith as well as the definition of whitespace should have been followed to the letter against the ES6 spec, which is why you're getting that result.
Note "Anthony Liatsis".startsWith("Anthony ".trim()) would perhaps be a bit simpler for you.
I was trying to test "Anthony Liatsis".startsWith("Anthony "). Each of the string values were stored in variables. The "Anthony " was retrieved via a regex in my code against the text of a contenteditable div. The startsWith() result was continually false. I discovered that the trailing space in "Anthony " was UTF-8 #160 which is a non-breaking space and was not equal to an empty string.
Doing "Anthony Liatsis".startsWith("Anthony ".replace(/\s/, " ")) made it work.
The text was updated successfully, but these errors were encountered: