반응형
C#에 있는 startsWith, endsWith 함수를 javascript에서도 쓸 수 있게 함수를 만들었다
startsWith
String.prototype.startsWith = function(str){
if (this.length < str.length) { return false; }
return this.indexOf(str) == 0;
}
endsWith
String.prototype.endsWith = function(str){
if (this.length < str.length) { return false; }
return this.lastIndexOf(str) + str.length == this.length;
}
반응형
'DEV > Javascript' 카테고리의 다른 글
| [Javascript]Array를 n개씩 나누기 (5) | 2017.03.15 |
|---|---|
| [Javascript]뒤로가기 이벤트 발생시 자바스크립트 실행하기 (1) | 2017.03.15 |
| [Angular]AngularJS 필터에서 $sce.trustAsHtml() 사용하기 (0) | 2017.03.15 |
| [Javascript]Object의 key값만 가져오기 (0) | 2017.03.15 |
| [Javascript]IE window.open사용권한이 없습니다 오류 (0) | 2017.03.14 |