
문자열을 결합시켜준다.
let firstName = "geun";
let secondName = "Lee";
let fullName = firstName.concat(secondName);
console.log(fullName);
출력
geunLee
문자열에 내용을 추가시켜준다.
let name = "geun";
name += " is programmer"
console.log(name);
출력
guen is programmer
문자열의 길이를 알려준다.
let name = "geun";
console.log(name.length);
출력
4
문자열의 대,소문자를 다룰수 있다.
let name = "Geun";
console.log(name);
console.log(name.toLowerCase());
console.log(name.toUpperCase());
출력
Geun
geun
GEUN
문자열을 자를때 사용한다. string.slice(start,end)에서 start는 시작지점, end는 끝 지점을 나타내어 문자열의 start부터 end전까지 잘라낸다.
let name = "geun";
console.log(name.slice(0,2));
console.log(name.slice(1,4));
출력
ge
eun
split은 문자열을 분리할 때, Join은 붙일 때 사용한다.
()안의 내용을 기준으로 분리하고, Join은 붙일 때 ()안의 내용을 포함하여 붙인다.
let name = "geun";
name = name.split("");
console.log(name);
console.log(name.join("-"));
출력
['g','e','u','n']
g-e-u-n
문자열이 해당 문자열을 포함하고 있는지 여부를 알고싶을 때 사용한다.
let word = "abcde";
console.log(word.includes('a'));
console.log(word.includes('f'));
출력
true
false
문자열의 양 끝의 공백을 제거할 때 사용한다.
let word = ' asd ';
console.log(word);
console.log(word.trim());
출력
asd
asd