๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

๋ฌธ์ž์—ด ๊ฒฐํ•ฉ2

[JAVASCRIPT] ๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ : repeat( ) ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ : ๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ : repeat() ์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ์ธ repeat()์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค! ๐Ÿ˜ #1. repeat( ) repeat() ๋ฉ”์„œ๋“œ๋Š” ๋ฌธ์ž์—ด์„ ์ฃผ์–ด์ง„ ํšŸ์ˆ˜๋งŒํผ ๋ฐ˜๋ณตํ•ด ๋ถ™์ธ ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ! replace( ) ์‚ฌ์šฉ ๋ฐฉ๋ฒ• ! "๋ฌธ์ž์—ด".replace("ํšŸ์ˆ˜๊ฐ’"); const str1 = "javascript"; const cirrentStr1 = str1.repeat(0); // '' const cirrentStr2 = str1.repeat(1); // javascript const cirrentStr3 = str1.repeat(2); // javascriptjavascript ! point ! ๋ฌธ์ž์—ด์˜ ๋ฐ˜๋ณต ํšŸ์ˆ˜๊ฐ’์€ ์–‘์˜ ์ •์ˆ˜์—ฌ์•ผ ํ•œ๋‹ค! 2022. 8. 18.
[JAVASCRIPT] ํ…œํ”Œ๋ฆฟ ๋ฌธ์ž์—ด ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ : ๋ฌธ์ž์—ด ๊ฒฐํ•ฉ : ํ…œํ”Œ๋ฆฟ ๋ฌธ์ž์—ด ์ง€๊ธˆ๋ถ€ํ„ฐ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ์˜ ๋ฌธ์ž์—ด ๊ฒฐํ•ฉ๊ณผ ๋ฌธ์ž์—ด ๋ฉ”์†Œ๋“œ์ธ ํ…œํ”Œ๋ฆฟ ๋ฌธ์ž์—ด์— ๋Œ€ํ•ด ์•Œ์•„๋ด…์‹œ๋‹ค! 1. ํ…œํ”Œ๋ฆฟ ๋ฌธ์ž์—ด ํ…œํ”Œ๋ฆฟ ๋ฌธ์ž์—ด( )์€ ๋ฌธ์ž์—ด ๊ฒฐํ•ฉ ๋ฉ”์„œ๋“œ๋กœ ๋‚ด์žฅ๋œ ํ‘œํ˜„์‹์„ ํ—ˆ์šฉํ•˜๋Š” ๋ฌธ์ž์—ด ๋ฆฌํ„ฐ๋Ÿด์ž…๋‹ˆ๋‹ค. ๋ฌธ์ž์—ด์„ ๊ฒฐํ•ฉํ•  ๋•Œ ๋”ฐ์˜ดํ‘œ ๋Œ€์‹  ` ` (backtick_๋ฐฑํ‹ฑ)์„ ์‚ฌ์šฉํ•˜๋ฉฐ ๋ณ€์ˆ˜๋ฅผ ๋„ฃ๊ณ ์ž ํ•˜๋Š” ๋ถ€๋ถ„์— ${}๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋„ฃ์–ด์ฃผ๋ฉด ๋ฉ๋‹ˆ๋‹ค. ๋˜ํ•œ ๊ฐ„๋‹จํ•œ ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ๋ฌธ๋ฒ•์„ ๋ฌธ์ž์—ด ์•ˆ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. //01. ๋ฌธ์ž์—ด(string) ๊ฒฐํ•ฉ const str1 = "์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ"; const str2 = "์ œ์ดํ€˜๋ฆฌ"; document.querySelector(".sample01_P1").innerHTML = str1 + str2; //02. ์ˆซ์ž(number) ๊ฒฐํ•ฉ.. 2022. 8. 18.
728x90
๋ฐ˜์‘ํ˜•

Lucky Charms Rainbow
js
html
css