js基础 字符串API梳理

43 阅读1分钟

使用频率:高

    1. slice(start[, end]): 截取字符串。
    1. split(separator[, limit]): 分割字符串。
    1. concat(str1, str2, ..., strN): 连接多个字符串。
    1. indexOf(searchValue[, fromIndex]): 返回指定值的第一次出现的位置。
    1. lastIndexOf(searchValue[, fromIndex]): 返回指定值的最后一次出现的位置。
    1. substring(start[, end]): 截取字符串。
    1. match(regexp): 使用正则表达式匹配字符串。
    1. search(regexp): 搜索字符串。 使用频率:一般
    1. charAt(index): 返回指定位置的字符。
    1. charCodeAt(index): 返回指定位置的字符的Unicode编码。
    1. replace(searchValue, replaceValue): 替换字符串中的指定值。
    1. localeCompare(string): 比较两个字符串。
    1. toLocaleLowerCase(): 转换为小写。
    1. toLocaleUpperCase(): 转换为大写。
    1. toLowerCase(): 转换为小写。
    1. toUpperCase(): 转换为大写。
    1. trim(): 去除字符串两端的空白字符。
    1. trimEnd(): 去除字符串末尾的空白字符。
    1. trimStart(): 去除字符串开头的空白字符。
    1. startsWith(searchString[, position]): 检查字符串是否以指定的子字符串开头。
    1. endsWith(searchString[, position]): 检查字符串是否以指定的子字符串结尾。
    1. repeat(count): 重复字符串。
    1. padStart(targetLength[, fillString]): 在字符串的开始填充字符串。
    1. padEnd(targetLength[, fillString]): 在字符串的末尾填充字符串。