Add space beginning of the string in typescript

To add space beginning of the string in typescript, use blank space with the + operator it will concatenate the string and return a new string with space.

let str: string = "infinitbility";

// add blank space
str = " " + str;
console.log(str) // 👉️ " infinitbility"

To show space at the beginning of the string you should put a blank space string before the + operator, like in the above example.

Add space at the end of the string in typescript

To space at the end of the string in typescript, use the + operator with a blank space string it will concatenate the string and return a new string with space.

let str: string = "infinitbility";

// add blank space
str =  str + " ";
console.log(str) // 👉️ "infinitbility "

To show space at the end of the string you should put a blank space string after the + operator, like in the above example.

Add space between string characters in typescript

To add space between string characters in typescript, use the split() with join() method with space separator it will add space for each character.

let str: string = "infinitbility";

// add blank space
str = str.split('').join(' ');

console.log(str) // 👉️ "i n f i n i t b i l i t y"

I hope it helps you, All the best 👍.