python - Is there a built-in javascript function similar to os.path.join? -


is there built-in javascript function functions python's os.path.join? know can join strings in following manner:

['a', 'b'].join('/') 

the problem if strings contain leading/trailing "/", not joined correctly, e.g.:

['a/','b'].join('/') 

edit: should have specified i'm doing client-side.

there isn't built-in perform join while preventing duplicate separators. if want concise, i'd write own:

function pathjoin(parts, sep){    var separator = sep || '/';    var replace   = new regexp(separator+'{1,}', 'g');    return parts.join(separator).replace(replace, separator); }  var path = pathjoin(['a/', 'b', 'c//']) 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -