⭐
🍌
☁️
✨
‹ 返回课程
字符串方法
编程代码 · JavaScript
💡 JavaScript 字符串常用方法:大小写、分割、查找、替换等
const upper = str.toUpperCase();↵// toUpperCase() 将字符串转为全大写
const trimmed = str.trim();↵// trim() 去除字符串两端的空格
const words = str.split(' ');↵// split(' ') 按空格分割成单词数组
const found = str.includes('hello');↵// includes() 检查是否包含指定子串,返回布尔值
const replaced = str.replace('old', 'new');↵// replace() 将第一个匹配的 'old' 替换为 'new'
const sub = str.substring(0, 5);// substring(0, 5) 截取前 5 个字符
0 字/分0% 准确
🐵
c左手中指
ESC 暂停⌫ 退格