You could strip the two strings of all the characters you want to ignore.
To strip a string of all the characters you don't want you can use the replace() function. By using \s we remove all spaces, tabs and new-lines, if you want something more specific you have to change the first argument of the replace() function.
string.replace(/\s+/g, '')
(see this SO-question to understand how it works: Remove whitespaces inside a string in javascript)
To compare two strings you could use
string1.localeCompare(string2)
(see this SO-question to understand how it works:
Optimum way to compare strings in JavaScript? )
If you put these two concepts together, you get
string1 = string1.replace(/\s+/g, '')
string2 = string2.replace(/\s+/g, '')
string1.localeCompare(string2)
which should answer your question.