Pad string with given length - Node.js String

Node.js examples for String:Padding

Description

Pad string with given length

Demo Code


Utils.pad = function(str, len, pad) {
  var str = ""+str;
  if (len > str.length) {
    return Array(len + 1 - str.length).join(pad) + str;
  }/* w  w w. j  a  v  a2s .c  o  m*/
  return str;
}

Related Tutorials