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?