JavaScript 문법 1

·2022년 12월 18일
0

study

목록 보기
5/81
post-thumbnail

문자열에서 특정 문자열 포함 여부 확인

1. ECMAScript 6부터 지원하는 includes 함수

  • 특정 문자열이 존재하면 true를 반환하며, 존재하지 않으면 false
  • 대소문자를 구분
str.includes(searchString[, position])

2. indexOf 함수

  • 특정 문자열이 존재하면 첫 번째 index를 반환하며, 존재하지 않으면 -1을 반환
  • 매개변수의 값(fromIndex)이 문자열의 길이(str.length)보다 크거나 같다면, 문자열을 검색하지 않고 -1을 반환
  • 대소문자를 구분
str.indexOf(searchValue[, fromIndex])

3. startsWith 함수

  • startsWith 함수는 문자열이 특정 문자열로 시작하는지 체크하는 함수
  • 대소문자를 구분
str.startsWith(searchString[, position])

4. endsWith 함수

  • 특정 문자열로 끝나는지 체크하는 함수
  • 대소문자를 구분
str.endsWith(searchString[, length])
profile
개발자 꿈나무

0개의 댓글