728x90
๋ฐ์ํ
11. ๋ฌธ์์ด ๋ฉ์๋ : ๋ณ๊ฒฝ : padStart() / padEnd() : ๋ฌธ์์ด ์ถ๊ฐ
padStart() / padEnd() ๋ฉ์๋๋ ์ฃผ์ด์ง ๊ธธ์ด์ ๋ง๊ฒ ์/๋ค ๋ฌธ์์ด์ ์ฑ์ฐ๊ณ , ์๋ก์ด ๋ฌธ์์ด์ ๋ฐํํฉ๋๋ค.
"๋ฌธ์์ด".padStart(๊ธธ์ด)
"๋ฌธ์์ด".padStart(๊ธธ์ด, ๋ฌธ์์ด)
const str1 = "456";
const currentStr1 = str1.padStart(1,"0"); //456
const currentStr2 = str1.padStart(2,"0"); //456
const currentStr3 = str1.padStart(3,"0"); //456
const currentStr4 = str1.padStart(4,"0"); //0456
const currentStr5 = str1.padStart(5,"0"); //00456
const currentStr6 = str1.padStart(6,"0"); //000456
const currentStr7 = str1.padStart(6,"1"); //111456
const currentStr8 = str1.padStart(6,"12"); //121456
const currentStr9 = str1.padStart(6,"123"); //123456
const currentStr10 = str1.padStart(6,"1234"); //123456
const currentStr11 = str1.padStart(6,""); // 456
const currentStr12 = str1.padEnd(1,"0"); // 456
const currentStr13 = str1.padEnd(2,"0"); // 456
const currentStr14 = str1.padEnd(3,"0"); // 4560
const currentStr15 = str1.padEnd(4,"0"); // 4560
const currentStr16 = str1.padEnd(5,"0"); // 45600
const currentStr17 = str1.padEnd(6,"0"); // 456000
const currentStr18 = str1.padEnd(6,"1"); // 456111
const currentStr19 = str1.padEnd(6,"12"); // 456121
const currentStr20 = str1.padEnd(6,"123"); // 456123
const currentStr21 = str1.padEnd(6,"1234"); // 456123
const currentStr22 = str1.padEnd(6); // 456___
728x90
๋ฐ์ํ
'์๋ฐ์คํฌ๋ฆฝํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
search() (5) | 2022.08.22 |
---|---|
includes() (5) | 2022.08.17 |
replace() / replaceAll() (4) | 2022.08.17 |
split() (4) | 2022.08.17 |
trim() / trimStart() / trimEnd() (4) | 2022.08.17 |
๋๊ธ