I have an string of the format
let a = "A B"
where there is a whitespace between the first part and the second.
When I try a.split(" "), it returns ["A B"], which is a array of length 1, containing the original string.
When I try a.split(/(\s+)/), I get the desired result, ["A", "B"]
The wierd thing is split(" ") only fails sometimes, in other times it works same as expected, I tried a couple of input but did not figure out the reason behind.
Does anyone have this problem before? This looks super weird.
UPDATE:
Sorry, I think oversimply the problem, so the string comes from innerText of a DOM object. Its original look is of the format {var1} {var2}
Is this where the problem comes from? Because I cannot find any other explanation, but this one still does not makes sense to me....