In VBScript, there is a space
function which takes an integer and returns a string with the specified number of spaces. At times, you may need such a function to make you text look neat while working with a monospace font. Here is the code that you could use to define your own space
function in JavaScript:
function space(num) {
return new Array(num + 1).join(" ");
}
Basically, the space
function creates an array of a length that is one more than the number that is specified. After that, the array of undefined
values is joined together with the delimiter of a space (thus the reason for using num + 1
to ensure the correct amount of spaces). Finally, this string of spaces is returned.
1 Comment
Chris West's Blog » VBScript To JavaScript – Space Function · July 5, 2011 at 7:52 PM
[…] See thе article here: Chris West's Blog » VBScript Tο JavaScript – Space Function […]