I am getting a string from an API that has some sort of spacing, string2
. On string2
the spaces are not regular spaces, I don't even know if they are tabs, but if I try to replace them still not equal to the spaced string1
.
// This string has normal spaces charCodeAt(4) displays '32'
const string1 = 'long string with spaces'
// This string has different spaces charCodeAt(4) displays '160'
const string2 = 'long string with spaces'.replace(/\s+/g, ' ')
console.log(string1)
console.log(string2)
console.log(string1 === string2)
--- Update
The problem was that I had a mixture of normal spaces and non-breaking spaces on string1
so it will never be equal to string2
no matter how much I changed string2
Since I do have control of the string1
, I have corrected it to have normal spaces and now it works.