Lukas Chen Lukas Chen - 2 months ago 5x
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);


A concise option:

function convertToSpace(n) {
  return new Array(n + 1).join(' ')