把字符串“javascript is awesome”替换成“j4v4scr1pt 1s 4w3s0m” var input="javascript is awesome"; var output=""; for(var i=0;i<input.length;i++){ output+=input[i]; output["a"]=["4"]; output["o"]=["0"]; output["i"]=["1"]; output["e"]=["3"]; } console.log(output)
3 回答
千秋此意
TA贡献158条经验 获得超187个赞
var input = 'javascript is awesome'; input = input.replace(/[aoie]/g, function(s) { return s === 'a' && '4' || s === 'o' && '0' || s === 'i' && '1' || s === 'e' && '3'; }); console.log(input); // => 'j4v4scr1pt 1s 4w3s0m3'
用replace试试
添加回答
举报
0/150
提交
取消