【发布时间】:2015-03-10 11:17:37
【问题描述】:
我有一个这样的关联数组/对象:
mymap = {'e':'f', 'l':'g'};
我想用上面的代码作为一个简单的密码替换字符串中的所有匹配字符,但只替换现有字符。例如,
input = "hello world";
output = input.map(mymap); //how can I do this?
//output is "hfggo worgd"
平衡性能(对于大输入)和代码大小很重要。
我的应用程序正在使用 this map 将 unicode 字符替换为乳胶字符串,但我很乐意坚持更一般的问题。
【问题讨论】:
标签: javascript replace associative-array