I have 2 strings that use the same letters but one of them contains empty spaces at the end and between words
const message = 'Hello javascript world ';
const message1 = 'Hello javascript world ' ;
i want to ignore these empty spaces from 2 strings to only compare strings by the rest of chars in order to get a boolean result equal to true when i do so message === message1
imo this need a regex
>Solution :
Yes, you can use str.replace(/\s+/g, '')
to remove the spaces then simply compare the strings
That would look something like this:
const message = 'Hello javascript world ';
const message1 = 'Hello javascript world ' ;
const equal = message.replace(/\s+/g, '') == message1.replace(/\s+/g, '');
// true