chartAt(索引),返回索引对应字符
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
// chartAt(索引),返回索引对应字符
var str = "xiaoming"
var str1 = str.charAt(0)
console.log(str,str1)
</script>
</body>
</html>
chartCodeAt(索引),返回索引对应的ascii编码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var str = "xiaoming"
// chartCodeAt(索引),返回索引对应的ascii编码
var str1 = str.charCodeAt(0)
console.log(str1)
</script>
</body>
</html>
toUpperCase()小写转大写 toLowerCase()大写转小写
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var str = "xiaoming"
var str1 = "XIAOMING"
// toUpperCase()小写转大写
console.log(str.toUpperCase())
// toLowerCase()大写转小写
console.log(str1.toLowerCase())
</script>
</body>
</html>
substr和substring
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
//截取 substr(开始索引,长度) substring(开始索引,结束索引) slice
var str1 = str.substr(0,2)
var str2 = str.substring(1,2)
var str3 = str.substring(1)
var str4 = str.slice(1,2)
var str5 = str.slice(1)
console.log(str1)
console.log(str2)
console.log(str3)
console.log(str4)
console.log(str5)
</script>
</body>
</html>
replace替换
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
var str = "xiaoming"
// replace只替换第一个
var str1 = str.replace("i","*")
console.log(str1)
</script>
</body>
</html>