Menu

gitpiper

indentString javascript Code Snippet in 2022

stringbeginner

Last Updated: 25 September 2022

Indents each line in the provided string.

  • Use String.prototype.replace() and a regular expression to add the character specified by indent count times at the start of each line.
  • Omit the third argument, indent, to use a default indentation character of ' '.
const indentString = (str, count, indent = ' ') => str.replace(/^/gm, indent.repeat(count));
indentString('Lorem\nIpsum', 2); // ' Lorem\n Ipsum' indentString('Lorem\nIpsum', 2, '_'); // '__Lorem\n__Ipsum'

javascript snippet similar to indentString For You in September 2022

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2022 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️