Lukas Chen Lukas Chen - 1 year ago 83
Javascript Question

Convert number into amount of space

I have a number and want it to generate to a string with corresponding space

For Example:

var NumberOfSpace = 3;

// This will result in a string with 3 empty space
// the result will be " "
var space = convertToSpace(NumberOfSpace);

Answer Source

A concise option:

function convertToSpace(n) {
  return new Array(n + 1).join(' ')
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download