let str = "Hello, World!";
let subStr = str.substring(0, 5); // subStr為"Hello"
let str = "Hello, World!";
let subStr = str.slice(0, 5); // subStr為"Hello"
let str = "Hello, World!";
let subStr = str.substr(0, 5); // subStr為"Hello"
let str = "Hello, World!"
let subStr = "";
for(let i = 0; i < 5; i++) {
subStr += str.charAt(i);
}
// subStr為"Hello"
這些是JavaScript中常用的字符串截取方法,可以根據具體的需求來選擇合適的方法。