최대 1 분 소요

string property

1. index of

  • 문자를 인수로 받아 몇번 째 함수인지 알려줌

  • 없는 문자를 입력하면 -1를 반환

  • 같은 단어가 여러 개이면 가장 빠른 단어를 반환

  • 0번째 인덱스 글자를 쓰면 fasle이기때문에 안됨. -1보다 커야함

image

2. toUpperCase / toLoewerCase

image

3. slice(n,m) / n 부터 m까지 숫자를 가져옴

image

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);

image

4. substring(n,m) n m사이문자열 변환

image

5. substr(n,m)/n부터 시작 m개를 가져옴

image

6. trim/앞뒤 공백제거

image

7. repeat / 반복

image

8. 문자 비교 (codePintAt/fromCodePoint)

image

  • a로부터 z 순, 대문자보다 숫자가 더 크다

9. Index of if문에 쓸때 주의사항!

function hasCola(str) {
  if (str.indexOf("콜라") > -1) {
    console.log("금칙어가 있습니다.");
  } else {
    console.log("통과");
  }
}
hasCola("와 사이다가 짱이야!");
hasCola("무슨소리, 콜라가 최고");
hasCola("그래 콜라!");

image

* 사실 includes를 하면 바로 나옴^^

댓글남기기