[JavaScript] String

Parkboss·2022년 3월 16일
0

JavaScript

목록 보기
16/29
post-thumbnail

String

문자 정의/표기

backslash 두개 시 출력은 backslash 하나만 출력된다.
\tfeed -> t는 tab으로 출력 시 스페이싱이 생긴다.

문자열 길이/접근

01234567891011121314
hello\nworld\n!!!

console.log(str.charCodeAt(1)); --> 101
'ASCII Code(아스키 코드)'는 숫자에 따라 문자 매핑을 확인할 수 있다.

문자열 검색/변환

01234567891011121314
hello,world!!!

console.log(text.indexOf("1",3)); --> 세번째서부터 출력해라! 3이 출력된다.
console.log(text.indexOf("1",4)); --> 네번째부터 I를 출력해라! 10이 출력된다.
console.log(text.lastIndexOf("1")); --> 마지막에서부터 I를 출력해라! 10이 출력된다.
console.log(text.starsWith("ello"); --> false 왜냐? 첫번째부터 찾기 때문에 hello해야 참이다.
console.log(text.starsWith("ello",1)); --> ture 왜냐? e가 1로 시작하기 떄문이다.

  • String.includes: 전체에서 ""가 있는지 확인
  • String.starsWith: 실제로 "" 시작하는지 확인
  • String.endsWith: 실제로 "" 뒤에서 시작하는지 확인
    (stars,ends는 좀더 세밀한 조건 판단할때 쓰는 메소드이다.)
profile
ur gonna figure it out. just like always have.

0개의 댓글