javaScript/JS Tutorial
[자바스크립트]endsWith() 끝나는 문자열 확인하기
mooyou
2022. 9. 27. 23:10
728x90
300x250
SMALL
endsWith()
endsWith()메서드는 문자열이 지정된 값으로 끝나면 true를 반환하고 그렇지 않으면 false를 반환
<p id="demo"></p>
<script>
let text = "Hello world, welcome to the universe.";
document.getElementById("demo").innerHTML = text.endsWith("universe.");
</script>
실행결과
true
text변수 안에 문장이 universe.로 끝나면 true 반환
검색 범위 지정하기
<p id="demo"></p>
<script>
let text = "Hello world, welcome to the universe.";
document.getElementById("demo").innerHTML = text.endsWith("world", 11);
</script>
실행결과
true
문자열 처음부터 11번째까지가 "world"로 끝나면 true반환
728x90
반응형
LIST