<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
</head>
<body>
</body>
<script>
//定义一个字符串
var str1 = "abc";
var str2 = 'ABC';
//定义字符串对象
var obj_str1 = new String("defg123123123123");
//强行转换函数 非字符串类型,强行转换为字符串,字符串类型原样输出
var obj_str2 = String("DEF");
// console.log(str1);
// console.log(str2);
// console.log(obj_str1);
// console.log(obj_str1[0]);
// console.log(obj_str1[1]);
// console.log(obj_str1[2]);
// console.log(typeof obj_str2);
// console.log(obj_str1.length);
//无论你用什么样的方式去创建出来的字符串,都可以使用对象的方式去控制
// console.log(str1[0]);
// console.log(str1[1]);
// console.log(str1[2]);
// console.log(str1.length);
// console.log(obj_str2[0]);
// console.log(obj_str2[1]);
// console.log(obj_str2[2]);
// console.log(obj_str2.length);
console.log(typeof str1);
console.log(typeof obj_str1);
</script>
</html>
String对象的创建
最新推荐文章于 2022-09-17 14:53:19 发布