1. 去首尾空格方法
trim()
方法会从一个字符串的两端删除空白字符
let str = " String ";
console.log(str.trim()); //===>'String'
2. 字符串查找
indexOf()
方法返回在数组中可以找到一个给定元素的第一个索引,如果不存在,则返回-1。
const str="we are the best"
console.log(str.indexOf("a")) //===>3
console.log(str.indexOf("c")) //===>-1
includes()
方法用于判断一个字符串是否包含在另一个字符串中,根据情况返回 true 或 false。
const str="we are the best"
console.log(str.includes("a")) //===>true
console.log(str.includes("c")) //===>false