faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

28 of 98 people (29%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

Is there a JavaScript method equivalent to the VBScript method Space()? Str=Str+Space(10000) adds 10000 blank spaces and no for()-looping is used.

Apr 4th, 2008 21:17
ha mo, Mark Szlazak, Richard Lowe, JScript message board at 4GuysFromRolla


One way of getting a white space string is with the following function.
    function space(cnt) {
        return (new Array(cnt + 1)).join('');
    }
    var whiteSpaces = space(10000);
A similar function could be used to get a string of repeating 
substrings.
    function repeats(str, cnt) { 
        return (new Array(cnt + 1)).join(str);
    }
    var str = repeats('hi ', 100);
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com