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

[JAVASCRIPT] ๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ : concat( )

by _ํ† ๋งคํ†  2022. 8. 18.
728x90

์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ : ๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ : concat()

์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ์ธ concat()์— ๋Œ€ํ•ด ์•Œ์•„๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค! ๐Ÿ˜


#1. concat( )

concat() ๋ฉ”์„œ๋“œ๋Š” ๋‘˜ ์ด์ƒ์˜ ๋ฌธ์ž์—ด์„ ๊ฒฐํ•ฉํ•˜์—ฌ, ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•ฉ๋‹ˆ๋‹ค. ์ฆ‰ ์—ฌ๋Ÿฌ๊ฐœ์˜ ๋ฌธ์ž์—ด์„ ํ•˜๋‚˜๋กœ ํ•ฉ์นœ๋‹ค๊ณ  ๋ณผ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

! replace( ) ์‚ฌ์šฉ ๋ฐฉ๋ฒ• !
"๋ฌธ์ž์—ด".concat("์ถ”๊ฐ€ํ•  ๋ฌธ์ž์—ด");
"๋ฌธ์ž์—ด".concat("์ถ”๊ฐ€ํ•  ๋ฌธ์ž์—ด", "์ถ”๊ฐ€ํ•  ๋ฌธ์ž์—ด"....); : ์—ฌ๋Ÿฌ๊ฐœ ์‚ฌ์šฉ ๊ฐ€๋Šฅ
"๋ฌธ์ž์—ด".concat("์ถ”๊ฐ€ํ•  ๋ฌธ์ž์—ด", ["์ถ”๊ฐ€ํ•  ๋ฌธ์ž์—ด"]); : ๋ฐฐ์—ด ์‚ฌ์šฉ ๊ฐ€๋Šฅ

const str1 = "javascript";

const cirrentStr1 = str1.concat("reference");                    // javascriptreference
const cirrentStr2 = str1.concat(" ", "reference");               // javascript reference
const cirrentStr3 = str1.concat(", ", "reference");              // javascript, reference
const cirrentStr4= str1.concat(", ", "reference", ", ", "book"); // javascript, reference, book
const cirrentStr5= str1.concat(",", ["refer", "book"]);          // javascript,refer,book

! point ! ๋ฌธ์ž์—ด์„ ๊ฒฐํ•ฉํ•  ๋• ๋ฌธ์ž์—ด์˜ ๋’ค์— ์ถ”๊ฐ€ ๋ฌธ์ž์—ด์ด ๋“ค์–ด๊ฐ€๋ฉฐ ๋ฌธ์ž์—ด ๋ฟ๋งŒ์•„๋‹ˆ๋ผ ๋ฐฐ์—ด๋„ ๊ฒฐํ•ฉ์ด ๊ฐ€๋Šฅํ•ฉ๋‹ˆ๋‹ค!

728x90

๋Œ“๊ธ€


Lucky Charms Rainbow
js
html
css