javascript-9: string-property
string property
1. index of
-
문자를 인수로 받아 몇번 째 함수인지 알려줌
-
없는 문자를 입력하면 -1를 반환
-
같은 단어가 여러 개이면 가장 빠른 단어를 반환
-
0번째 인덱스 글자를 쓰면 fasle이기때문에 안됨. -1보다 커야함
2. toUpperCase / toLoewerCase
3. slice(n,m) / n 부터 m까지 숫자를 가져옴
const list = [
'01. 들어가며',
'02.JS의 역사',
'03. 자료형',
'04.함수'];
const newlist = [];
for(let i=0; i<list.length; i++) {
newlist.push(list[i].slice(4));
}
console.log(newlist);
4. substring(n,m) n과 m사이문자열 변환
5. substr(n,m)/n부터 시작 m개를 가져옴
6. trim/앞뒤 공백제거
7. repeat / 반복
8. 문자 열 비교 (codePintAt/fromCodePoint)
- a로부터 z 순, 대문자보다 숫자가 더 크다
9. Index of를 if문에 쓸때 주의사항!
function hasCola(str) {
if (str.indexOf("콜라") > -1) {
console.log("금칙어가 있습니다.");
} else {
console.log("통과");
}
}
hasCola("와 사이다가 짱이야!");
hasCola("무슨소리, 콜라가 최고");
hasCola("그래 콜라!");
* 사실 includes를 하면 바로 나옴^^
댓글남기기