the murmurous sea

JS: padStart() & padEnd() 본문

#dev/개념정리

JS: padStart() & padEnd()

lunacer 2020. 5. 4. 11:55

padStart()

1. pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length.

2. The padding is applied from the start of the current string.

 

[Syntax]

str.padStart(targetLength [, padString])
targetLength   The length of the resulting string once the current str has been padded. 
    If the value is less than str.length, then str is returned as-is.
padString Optional The string to pad the current str with.
    If padString is too long to stay within the targetLength, it will be truncated from the end. 
    The default value is " " (U+0020 'SPACE').

 

[Return Value]

A String of the specified targetLength with padString applied from the start of the current str.

 

padEnd()

1. pads the current string with a given string (repeated, if needed) so that the resulting string reaches a given length.
2. The padding is applied from the end of the current string.

[Syntax]

str.padEnd(targetLength [, padString])
targetLength   The length of the resulting string once the current str has been padded. 
If the value is lower than str.length, the current string will be returned as-is.
padString Optional The string to pad the current str with.
If padString is too long to stay within targetLength, it will be truncated
The default value for this parameter is " " (U+0020 'SPACE').

 

[Return Value]

A String of the specified targetLength with the padString applied at the end of the current str.

 


https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd

'#dev > 개념정리' 카테고리의 다른 글

JS, ES1: splice()  (0) 2020.05.04
JS, ES1: split()  (0) 2020.05.04
[HTML DOM] DocumentFragment  (0) 2020.05.02
HTML DOM: insertBefore()  (0) 2020.05.02
선언적 함수 vs 함수표현식 vs 익명함수 (waiting list)  (0) 2020.05.02
Comments