String:
String字符串对象创建方法有两种:
方式一:
var str = new String("Hello String");
方式二:
var str = "Hello String";
常见的属性和方法:
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Js-对象-String</title>
</head>
<body>
<script>
// 创建字符串对象
// var str = new String("Hello String");
var str = " Hello String ";
console.log(str);
// 字符串的属性length
console.log(str.length);
// charAt()
console.log(str.charAt(4));
// indexOF()
console.log(str.indexOf("String"));
// trim
console.log(str.trim());
// substring()
console.log(str.substring(0, 8))
</script>
</body>
</html>