<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
</style>
</head>
<body>
<script>
var txt = "hello world,hello abc";
var txt2 = "jie";
var txt3 = "how are you doing today"
// document.write(txt.length); 11
// document.write(txt.charAt(1)) e
// document.write(txt.concat(txt2)) hello world,hello abcjie
// document.write(txt.indexOf("hello")); 0
// document.write(txt.indexOf("world")); 6
// document.write(txt.indexOf("World")); -1
// document.write(txt.replace(/hello/,"jie")) jie world,hello abc
// document.write(txt.replace(/hello/g,"jie")) jie world,jie abc
// document.write(txt.search(/world/)) 6
// document.write(txt.search(/worldss/)) -1
// document.write(txt.search(/World/i)) 6
// document.write(txt.slice(6)); world,hello abc
// document.write(txt.slice(2,7)); llo world,hello abc
// document.write(txt3.split(" ") + "<br/>") how,are,you,doing,today
// document.write(txt3.split("") + "<br/>") h,o,w, ,a,r,e, ,y,o,u, ,d,o,i,n,g, ,t,o,d,a,y
// document.write(txt3.split(" ",3)) how,are,you
</script>
</body>
</html>
複製程式碼