728x90
๋ฐ์ํ
09. ๋ฌธ์์ด ๋ฉ์๋ : ๋ณ๊ฒฝ : split() : ๋ฌธ์์ด์์ ์ํ๋ ๊ฐ์ ์ถ์ถ
๋ฌธ์์ด์์ ์ํ๋ ๊ฐ์ ์ถ์ถํ๋ ๋ฉ์๋์
๋๋ค.
"๋ฌธ์์ด".split(๊ตฌ๋ถ์);
"๋ฌธ์์ด".split(์ ๊ท์ ํํ);
"๋ฌธ์์ด".split(๊ตฌ๋ถ์, ๊ฐฏ์);
"๋ฌธ์์ด".split(์ ๊ท์ ํํ);
"๋ฌธ์์ด".split(๊ตฌ๋ถ์, ๊ฐฏ์);
const str1 = "javascript reference";
const currentStr1 = str1.split(''); //[0: "j"1: "a"2: "v"3: "a"4: "s" 5: "c"6: "r"7: "i"8: "p"9: "t"10: " "11: "r"12: "e"13: "f"14: "e"15: "r"16: "e"17: "n"18: "c"19: "e"]
const currentStr2 = str1.split(''); //['javascript', 'reference']
const currentStr3 = str1.split('', 1); //['j']
const currentStr4 = str1.split('', 2); //['j', 'a']
const currentStr5 = str1.split(' ', 1); //['javascript']
const currentStr6 = str1.split(' ', 2); //['javascript', 'reference']
const currentStr7 = str1.split('j'); //['', 'avascript reference']
const currentStr8 = str1.split('a'); //['j', 'v', 'script reference']
const currentStr9 = str1.split('e'); //['javascript r', 'f', 'r', 'nc', '']
const str2 = "java/script/refer/ence";
const currentStr10 = str2.split('/'); //['java', 'script', 'refer', 'ence']
const str3 = "java&script&refer!ence";
const currentStr11 = str3.split('!'); //['java&script&refer', 'ence']
const currentStr12 = str3.split('&'); //['java', 'script', 'refer!ence']
const currentStr13 = str3.split(/&|\!/); //['java', 'script', 'refer', 'ence']
const str4 = "javascript reference";
const currentStr14 = str4.split('').join(); //j,a,v,a,s,c,r,i,p,t, ,r,e,f,e,r,e,n,c,e //๋ฐฐ์ด์ด ์ฌ๋ผ์ง
const currentStr15 = str4.split('').join('*'); //j*a*v*a*s*c*r*i*p*t* *r*e*f*e*r*e*n*c*e
const currentStr16 = str4.split('').reverse().join(); //e,c,n,e,r,e,f,e,r, ,t,p,i,r,c,s,a,v,a,j
const currentStr17 = str4.split('').reverse().join('/'); //e/c/n/e/r/e/f/e/r/ /t/p/i/r/c/s/a/v/a/j
728x90
๋ฐ์ํ
'์๋ฐ์คํฌ๋ฆฝํธ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
padStart() / padEnd() (5) | 2022.08.17 |
---|---|
replace() / replaceAll() (4) | 2022.08.17 |
trim() / trimStart() / trimEnd() (4) | 2022.08.17 |
๋ฌธ์์ด ๊ฒฐํฉ / ํ ํ๋ฆฟ ๋ฌธ์์ด (3) | 2022.08.17 |
toUpperCase() / toLowerCase() (4) | 2022.08.17 |
๋๊ธ