padStart
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/padStart
padEnd
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/padEnd
padEnd()
๋ฉ์๋๋ ํ์ฌ ๋ฌธ์์ด์ ๋ค๋ฅธ ๋ฌธ์์ด์ ์ฑ์, ์ฃผ์ด์ง ๊ธธ์ด๋ฅผ ๋ง์กฑํ๋ ์๋ก์ด ๋ฌธ์์ด์ ๋ฐํํ๋ค.
์ฑ์๋ฃ๊ธฐ๋ ๋์ ๋ฌธ์์ด์ ๋(์ฐ์ธก)๋ถํฐ ์ ์ฉ๋๋ค.
const str1 = 'Breaded Mushrooms';
console.log(str1.padEnd(25, '.'));
// expected output: "Breaded Mushrooms........"
const str2 = '200';
console.log(str2.padEnd(5));
// expected output: "200 "
padEnd()
์ ์ฑ์๋ฃ๊ธฐ๊ฐ ๋์ ๋ฌธ์์ด์ ๋(์ฐ์ธก)๋ถํฐ ์ ์ฉ๋์๋ค๋ฉด,
padEnd()
์ ์ฑ์๋ฃ๊ธฐ๋ ๋์ ๋ฌธ์์ด์ ์์(์ข์ธก)๋ถํฐ ์ ์ฉ๋๋ค.
const str1 = '5';
console.log(str1.padStart(2, '0'));
// expected output: "05"
const fullNumber = '2034399002125581';
const last4Digits = fullNumber.slice(-4);
const maskedNumber = last4Digits.padStart(fullNumber.length, '*');
console.log(maskedNumber);
// expected output: "************5581"