function foo(str) { for(var i=1;i<arguments.length;i++){ str=str.replace('%'+(i-1),arguments[i]) } return str } alert(foo("%2%3%4%5%0%1","гн", "я","вс" ,"як","ая"," фи"))