JAVASCRIPT - HOW TO Trim Lines of Array & Add Padding - Javascript Source Code

JAVASCRIPT - HOW TO Trim Each Line of Array and Add Left and Right Space Padding to Each Line of Array

Home Short:

The function below takes a multiline string, splits the string line by line, and optionally adds your desired number of spaces before and after each line.

Most of the parameters of the Javascript function are optional with default values for the purpose of making this function as flexible as possible, such as the padding at the beginning and end of the string. For this reason, several examples of ways of using the function to split a string and add padding will be shown below.

Example of Using the Function to Split String Line by Line, Trim Beginning of Each Line, with NO Padding Added to the Lines

Split Above Text into Line by Line Array and Trim ...

S
H
A
R
E