Directly upload code and screenshots
The results of the operation are as follows:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>javaScript中slice()函数</title>
<style type="text/css">
input[type=button] {
background-color: #8E388E;
border: 0px solid #8E388E;
color: #fff;
width: 160px;
height: 40px;
border-radius: 6px; /*把边框做成圆角*/
}
</style>
<script type="text/javascript">
function fn1() {
var testStr = "[object Object]";
//slice(startIndex, endIndex)注意:不包括endIndex
//-1表示最后一个字符的下标位置,-2表示倒数第二个字符的下标位置,-3,-4等等,以此类推
console.log(testStr, testStr.slice(8, -1));
//赣州市于都县渡江大
console.log(testStr, "江西省赣州市于都县渡江大道".slice(3, -1));
}
</script>
</head>
<body style="background-color: #CCE8CF;">
<h1>javaScript中slice()函数</h1>
<input type="button" value="字符串的slice()函数" onclick="fn1();">
<div id="div1" style="background-color: Wheat; height: 100%;">
</div>
</body>
</html>
I've been lazy lately, so it's not good!