javascript - replacing special characters with other character from array in js -


i rid of special characters in string comparing each of it's character character in array , replacing matching one. function below not throw errors keeps returning string unchanged

    var name = "przykład";            // characters i'm looking in string:     var charlist = ["Ą","ą","Ć","ć","Ę","ę","Ł","ł","Ó","ó","Ś","ś","Ź","ź","Ż","ź"];      // characters i'd replace them with:     var replacelist = ["a","a","c","c","e","e","l","l","o","o","s","s","z","z","z","z"];      var limit = name.length;     (i = 0; < limit; i++){         for(var j in charlist){             name.charat(i) === charlist[j] ? name.replace(name.charat(i), replacelist[j]) : "";         }     }      return name; 

i know question closed "too localized" , it's propably stupid , easy mistake i've made still appreciate this

usually, result of replace function returned new string object in of programming languages. should change code this:

if (name.charat(i) === charlist[j])     name = name.replace(name.charat(i), replacelist[j]); 

also, since replace function replace all occurrences of character, change algorithm little bit.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -