Join URL Paths

Join URL path segments properly handling slashes.

Code

Utilities
segments.map(s => s.replace(/^\/|\/$/g, '')).filter(Boolean).join('/').replace(':/', '://');

Parameters

Array of path segments.

Browser·fetch() may be limited by CORS

More JavaScript Snippets