
HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>string 의 method 에 대해서 알아봅니다. -1</title>
<script type="text/javascript" src="js/02.js"></script>
</head>
<body>
<h2>
문자열.slice(startIndex, endIndex) <br>
문자열.substring(startIndex, endIndex) <br>
문자열.substr(startIndex, length) <br>
</h2>
<p id="slice_forward"></p>
<p id="slice_reverse"></p>
<p id="substring"></p>
<p id="substr_forward1"></p>
<p id="substr_forward2"></p>
<p id="substr_reverse1"></p>
<p id="substr_reverse2"></p>
<p id="str"></p>
</body>
</html>
JS
window.onload = function(){
const str = "Apple, Banana, Kiwi";
let part = str.slice(7, 13);
document.getElementById("slice_forward").innerHTML = part;
part = str.slice(-12, -6);
document.getElementById("slice_reverse").innerHTML = part;
part = str.substring(7, 13);
document.getElementById("substring").innerHTML = part;
part = str.substr(7,6);
document.getElementById("substr_forward1").innerHTML = part;
part = str.substr(7);
document.getElementById("substr_forward2").innerHTML = part;
part = str.substr(-12,6);
document.getElementById("substr_reverse1").innerHTML = part;
part = str.substr(-12);
document.getElementById("substr_reverse2").innerHTML = part;
document.getElementById("str").innerHTML = str;
}
정리
- 06_string
-> 02_string_method_1, 02.js