๋ฌธ์์ด ๋ณ๊ฒฝ ๋ฉ์๋ : padStart() / padEnd()
padStart() / padEnd() ๋ฉ์๋๋ ์ฃผ์ด์ง ๊ธธ์ด์ ๋ง๊ฒ ์ / ๋ค ๋ฌธ์์ด์ ์ฑ์ฐ๊ณ , ์๋ก์ด ๋ฌธ์์ด์ ๋ฐํํฉ๋๋ค.
padStart() ๋ฉ์๋
padStart() ๋ฉ์๋๋ ํ์ฌ ๋ฌธ์์ด์ ์์์ ๋ค๋ฅธ ๋ฌธ์์ด๋ก ์ฑ์, ์ฃผ์ด์ง ๊ธธ์ด๋ฅผ ๋ง์กฑํ๋ ์๋ก์ด ๋ฌธ์์ด์ ๋ฐํํฉ๋๋ค. ์ฑ์๋ฃ๊ธฐ๋ ๋์ ๋ฌธ์์ด์ ์์(์ข์ธก)๋ถํฐ ์ ์ฉ๋ฉ๋๋ค.
const str1 = "456";
const currentStr1 = str1.padStart(1, "0"); // ํ์ฌ ๋ฌธ์์ด์ ๊ธธ์ด๋ณด๋ค ์๋ค๋ฉด, ์ฑ์๋ฃ์ง ์๊ณ ๊ทธ๋๋ก ๋ฐํํฉ๋๋ค.
const currentStr2 = str1.padStart(2, "0");
const currentStr3 = str1.padStart(3, "0");
const currentStr4 = str1.padStart(4, "0");
const currentStr5 = str1.padStart(5, "0");
const currentStr6 = str1.padStart(6, "0");
const currentStr7 = str1.padStart(6, "1");
const currentStr8 = str1.padStart(6, "12");
const currentStr9 = str1.padStart(6, "123");
const currentStr10 = str1.padStart(6, "1239");
const currentStr11 = str1.padStart(6); // ๋ฌธ์์ด์ ์์ฑํ์ง ์์ผ๋ฉด, ๋จ๋ ๊ธธ์ด๋งํผ ๊ณต๋ฐฑ ์ฒ๋ฆฌ๋ฉ๋๋ค.
๊ฒฐ๊ณผ๋ณด๊ธฐ
456
456
0456
00456
000456
111456
121456
123456
123456
___456
padEnd() ๋ฉ์๋
padEnd() ๋ฉ์๋๋ ํ์ฌ ๋ฌธ์์ด์ ๋์ ๋ค๋ฅธ ๋ฌธ์์ด๋ก ์ฑ์, ์ฃผ์ด์ง ๊ธธ์ด๋ฅผ ๋ง์กฑํ๋ ์๋ก์ด ๋ฌธ์์ด์ ๋ฐํํฉ๋๋ค. ์ฑ์๋ฃ๊ธฐ๋ ๋์ ๋ฌธ์์ด์ ๋(์ฐ์ธก)๋ถํฐ ์ ์ฉ๋ฉ๋๋ค.
const str1 = "456";
const currentStr1 = str1.padEnd(1, "0");
const currentStr2 = str1.padEnd(2, "0");
const currentStr3 = str1.padEnd(3, "0");
const currentStr4 = str1.padEnd(4, "0");
const currentStr5 = str1.padEnd(5, "0");
const currentStr6 = str1.padEnd(6, "0");
const currentStr7 = str1.padEnd(6, "1");
const currentStr8 = str1.padEnd(6, "12");
const currentStr9 = str1.padEnd(6, "123");
const currentStr10 = str1.padEnd(6, "1239");
const currentStr11 = str1.padEnd(6);
๊ฒฐ๊ณผ๋ณด๊ธฐ
456
456
4560
45600
456000
456111
456121
456123
456123
456___
'Javascript' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์๋ฐ์คํฌ๋ฆฝํธ : ๋ฌธ์์ด ๊ฒ์ ๋ฉ์๋ : search() (9) | 2022.08.22 |
---|---|
์๋ฐ์คํฌ๋ฆฝํธ : ๋ฌธ์์ด ๊ฒ์ ๋ฉ์๋ : includes() (6) | 2022.08.17 |
์๋ฐ์คํฌ๋ฆฝํธ : ๋ฌธ์์ด ๋ณ๊ฒฝ ๋ฉ์๋ : split() (5) | 2022.08.17 |
์๋ฐ์คํฌ๋ฆฝํธ : ๋ฌธ์์ด ๋ณ๊ฒฝ ๋ฉ์๋ : repeat() (5) | 2022.08.17 |
์๋ฐ์คํฌ๋ฆฝํธ : ๋ฌธ์์ด ๋ณ๊ฒฝ ๋ฉ์๋ : concat() (3) | 2022.08.17 |
๋๊ธ