I want to write a javascript function to format message, this is my code:
pattern = "{0},{1}";
args = ["hello", "world"];
pattern.replace(/\{(\d+)\}/g, args["$1"*1]); //$1 stands for \d+, multiply 1 to convert it to a number
I want the result is hello,world, but it is undefined,undefined.
so how to change it to make it correct ?
"$1"*1returnsNaN. Which is not an index on the args array