字符串的 substring() 方法

了解 JavaScript 字符串的 substring() 方法 substring() 方法返回字符串的一部分,它与 slice() 方法相似,但有一些关键区别。 如果任何参数为负数,则会被转换为 0。 如果任何参数大于字符串的长度,则会被转换为字符串的长度。 所以: 'This is my car'.substring(5) //'is my car' 'This is my car'.substring(5, 10) //'is my' 'This is my car'.substring(5, 200) //'is my car' 'This is my car'.substring(-6) //'This is my car' 'This is my car'.substring(-6, 2) //'Th' 'This is my car'.substring(-6, 200) //'This is my car'