📜  切片 javascript 字符串 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:29.798000             🧑  作者: Mango

代码示例6
let str = "Learning to code";

// slice from index 2 to end
let str1 = str.slice(2);
console.log(str1);

// slice from index 1 to index 8
let str2 = str.slice(1, 8);
console.log(str2);

// slice from index 5 to index (str.length - 3)
let str3 = str.slice(5, -3);
console.log(str3);

// slice from index 100 to end (returns '')
let str4 = str.slice(100);
console.log(str4);

// slice from index 0 to end of string
let str5 = str.slice(0);
console.log(str5);