发布于 2023-11-03 11:12:18 浏览 252 次
let str = "Hello, world!";
let index = str.indexOf("world");
console.log(index); // 输出:7
let str = "Hello, world!";
let lastIndex = str.lastIndexOf("o");
console.log(lastIndex); // 输出:7
let str = "Hello, world!";
let hasWorld = str.includes("world");
console.log(hasWorld); // 输出:true
let str = "Hello, world!";
let index = str.search(/world/i);
console.log(index); // 输出:7
let str = "Hello, world!";
let index = str.toLowerCase().indexOf("world".toLowerCase());
console.log(index); // 输出:7