Reputation: 873
This is an odd one! I kind of want to say the reason my replace
function isn't working correctly is because of the font. I've never seen this issue before, and I wonder if I'm overlooking something!?
I have the following variable set to a static text with '
.
var lastName = "O'Donnell";
In my browser, console.log(lastName)
outputs: O’Donnell
. Instead of O'Donnell
. Therefore, the following replace method isn't working.
return lastName.replace(/'/g, '')
What am I doing wrong?
Upvotes: 1
Views: 3136
Reputation: 4618
The character you're trying to replace isn't the same as the one in the name.
Best to remove all non alpha numeric characters instead, to cater for names such as:
Try:
lastName.replace(/\W/g, '')
Upvotes: 8