我有一個需要被替換幾次的大字符串。如(多個)用數組替換字符串
var str="Username:[UN] Location:[LC] Age:[AG] ... "
str=str.replace("[UN]","Ali")
str=str.replace("[LC]","Turkey")
str=str.replace("[AG]","29")
...
//lots of replace
...
有沒有辦法將這些FIND和REPLACE參數放到一個數組中,並且一次全部替換它們?如:
reps = [["UN","Ali"], ["LC","Turkey"], ["AG","29"], ...]
$(str).replace(reps)
@KrzysztofSafjanowski應該反過來,因爲這是一個比你重複的提案 – 2016-11-03 11:38:13