发布于 2023-11-04 17:37:53 浏览 150 次
var str = "Hello World";var lastChar = str[str.length - 1];console.log(lastChar); // 输出:d
var str = "Hello World";var lastChar = str.length > 0 ? str[str.length - 1] : "";console.log(lastChar); // 输出:d