Posted By

higeorange on 05/30/08


Tagged

javascript


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

korzhik


Array print


 / Published in: JavaScript
 

  1. function printArray(format, arry) {
  2. var i = 0;
  3. return format.replace(/%s/g, function($0) {
  4. return arry[i++];
  5. });
  6. }
  7.  
  8.  
  9. var a = ["foo", "bar", 1]
  10. printArray("%s+%s, %s 2 3", a); // foo+bar, 1 2 3

Report this snippet  

You need to login to post a comment.