Javascript replacing single quote with empty string -
this odd one! kind of want reason replace function isn't working correctly because of font. i've never seen issue before, , wonder if i'm overlooking something!?
i have following variable set static text '.
var lastname = "o'donnell"; in browser, console.log(lastname) outputs: o’donnell. instead of o'donnell. therefore, following replace method isn't working.
return lastname.replace(/'/g, '') what doing wrong?
the character you're trying replace isn't same 1 in name.
best remove non alpha numeric characters instead, cater names such as:
- o'neill
- st. mary's
try:
lastname.replace(/\w/g, '') 
Comments
Post a Comment