-1

Currently, I got let str = 'prefix' which has length of 6, but I would like to add empty space at the end and update it to str = 'prefix ' with length of 7.

I have tried str.split("").push("").join("") but I get error saying join is not a function. I have also tried str[str.length] = ' ', but this doesn't work either. What other options do I have?

Judoboy Alex
  • 326
  • 1
  • 14

1 Answers1

3

You can concatenate the strings:

let str = 'prefix';
str = str + ' ';
// str === 'prefix '

or, if you want to pad any sized string to a specified length:

let str = 'prefix';
str = str.padEnd(7, " ");
// str === 'prefix '
pfg
  • 2,348
  • 1
  • 16
  • 37