concat拼接
和+号一样
<!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"
// concat连接字符串
var str1 = str.concat("qqqqqqqq")
console.log(str1)
</script>
</body>
</html>
trim 去掉首尾空格
trimStart() trimLeft()去掉首空格
trimEnd() trimRight()去掉尾空格
<!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 = " xiao ming "
// trim 去掉首尾空格
// trimStart() trimLeft()去掉首空格
// trimEnd() trimRight()去掉尾空格
console.log("|"+str+"|")
console.log("|"+str.trim()+"|")
console.log("|"+str.trimStart()+"|")
console.log("|"+str.trimEnd()+"|")
</script>
</body>
</html>
split分割
<!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>
// split 分割
var str = "a,b,c,d"
console.log(str.split(","))
</script>
</body>
</html>
indexOf()和lastIndexOf()
能查到返回索引位置,不存在返回-1,返回找到的第一个值的索引
indexOf()从前往后查
lastIndexOf()从后往前查
<!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"
console.log(str.indexOf("i"))
console.log(str.indexOf("w"))
console.log(str.lastIndexOf("a"))
</script>
</body>
</html>