Indent String

Add indentation to each line of a string.

Code

General
str.replace(/^/gm, ' '.repeat(spaces));

Parameters

Multi-line string

Number of spaces to indent

Browser·fetch() may be limited by CORS

More JavaScript Snippets