string.concat

๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์ „๋‹ฌ๋ฐ›์€ ๋ชจ๋“  ๋ฌธ์ž์—ด์„ ๋ฌธ์ž์—ด๊ณผ ์—ฐ๊ฒฐํ•˜์—ฌ ์ƒˆ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

const str1 = "Hello";
const str2 = "world";

console.log(str1.concat(' ', str2)); // Hello world

Syntax

str.concat(str2 [, ...strN])

Parameters

str2, [, ...strN]

str์— ์—ฐ๊ฒฐ์‹œํ‚ฌ String

Return Value

์ œ๊ณต๋œ ๋ฌธ์ž์—ด์„ ์กฐํ•ฉํ•œ ์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด

Description

์ƒˆ๋กœ์šด ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•˜๊ธฐ ๋•Œ๋ฌธ์— ์›๋ณธ ๋ฌธ์ž์—ด ๋ณ€ํ˜•๋˜๊ฑฐ๋‚˜ ์˜ํ–ฅ์„ ๋ผ์น˜์ง€ ์•Š๋Š”๋‹ค. ๋ฌธ์ž์—ด์€ ๋ถˆ๋ณ€ ๊ฐ’ Immutable.. ์ธ์ž์˜ ๊ฐ’์˜ type string์ด ์•„๋‹ˆ๋ฉด ์—ฐ๊ฒฐ์‹œํ‚ค๊ธฐ ์ „์˜ ๋ฌธ์ž์—ด์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

Performance

concat() ๋ฉ”์†Œ๋“œ ๋Œ€์‹ ์— ํ• ๋‹น ์—ฐ์‚ฐ์ž ("+", "+=")๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ์ด ๊ฐ•๋ ฅํžˆ ๊ถŒ์žฅํ•œ๋‹ค.

ํ• ๋‹น ์—ฐ์‚ฐ์ž๊ฐ€ ๋” ๋น ๋ฅด๋‹ค.

Examples

const hello = "์•ˆ๋…•, ";
hello.concat("sla", ". ์ข‹์€ ํ•˜๋ฃจ ๋ณด๋‚ด"); // "์•ˆ๋…•, sla. ์ข‹์€ ํ•˜๋ฃจ ๋ณด๋‚ด"

const greetArr = ['Hello', ' ', 'sla', '!'];
''.concat(...greetArr); // "Hello sla!"


// If the arguments are not of the type string, they are converted to string values before concatenating. ์ด ์„ค๋ช…์ด๋ž‘ ์•ˆ๋งž๋Š” ๋А๋‚Œ.. 
"".concat({}); // [object Object] ๐Ÿค”
"".concat([]); // ""
"".concat(function(a) => return a); // "(a) => a"
"".concat(null); // "null"
"".concat(true); // "true"
"".concat(4, 5); // "45"

Last updated

Was this helpful?