๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ

split()

by Youcodein 2022. 8. 17.
728x90
๋ฐ˜์‘ํ˜•

09. ๋ฌธ์ž์—ด ๋ฉ”์„œ๋“œ : ๋ณ€๊ฒฝ : 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

๋Œ“๊ธ€