본문 바로가기
Javascript

문자열 메서드 : startsWidth() / endsWidth()

by 코딩 척척학사 2022. 9. 27.
728x90

문자열 메서드 : startsWidth() / endsWidth()

> startsWidth() / endsWidth() 메서드

startWidth() 메서드는 시작하는 분자열에서 문자열을 검색하여 불린(true, false)으로 반환합니다. endsWidth() 메서드는 끝나는 문자열에서 문자열을 검색하여 불린(true, false)으로 반환합니다.

"문자열".startsWidth(검색 문자열);
"문자열".startsWidth(검색 문자열, 위치값);
"문자열".endsWidth(검색 문자열);
"문자열".endsWidth(검색 문자열, 시작 위치값);
const str1 = "javascript reference";
const currentStr1 = str1.startsWith("javascript"); //true
const currentStr2 = str1.startsWith("j"); //true
const currentStr3 = str1.startsWith("java"); //true
const currentStr4 = str1.startsWith("reference"); //false
const currentStr5 = str1.startsWith(); //false
const currentStr6 = str1.startsWith(""); //true
const currentStr7 = str1.startsWith("reference", 7); //false
const currentStr8 = str1.startsWith("reference", 11); //true

const currentStr9 = str1.endsWith("reference"); //true
const currentStr10 = str1.endsWith("e"); //true
const currentStr11 = str1.endsWith("refer"); //false
const currentStr12 = str1.endsWith("javascript"); //false
const currentStr13 = str1.endsWith(); //false
const currentStr14 = str1.endsWith(""); //true
const currentStr15 = str1.endsWith("reference", 7); //false
const currentStr16 = str1.endsWith("reference", 20); //true
728x90

'Javascript' 카테고리의 다른 글

배열 메서드2  (6) 2022.09.27
MySQL 알아보기  (4) 2022.09.14
이벤트 메서드 알아보기 : mouseenter / mouseover  (2) 2022.09.06
문자열 결합과 템플릿 문자열  (14) 2022.09.01
문자열 메서드 : split()  (3) 2022.09.01

댓글


HTML이 적힌 썸네일 이미지
CSS가 적힌 썸네일 이미지
JAVASCRIPT가 적힌 썸네일 이미지

JAVASCRIPT

자세히 보기