Advertisement
B1KMusic

JavaScript format()

Apr 29th, 2019
387
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function format(str, ...args){
  2.     return str.split(/(%)/).map(part => (part == "%") ? (args.shift()) : (part)).join("");
  3. }
  4.  
  5. // Example use: format("Hello %, you have visited % times. You are %% of the way there.", username, numVisits, percent, "%")
  6. // "Hello Troomp, you have visited 420 times. You are 69% of the way there."
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement