I have to arrays that contain names of premier league players.
I want to match them by name since the player objects don't have unique ids.
How can I make a string comparison that will match
It is not a trivial problem. You should look into Levenshtein distance problem
You can search in google for different implementations or use a library like: https://www.npmjs.com/package/levenshtein
l = new Levenshtein( 'Zlatan Ibrahimovic', 'Zlatan Ibrahimović') // l === 1
I used already, and I liked. In my code, I used this one for an experimental proposed.
I don;t care about the result. Because in a long string 4 can be a very good number and in small one 2 it is very bad.
I get to do something like l/Math.max(str1.length, str2.length) then you can make your number and decide wich number is interesting for you.