admin 管理员组文章数量: 1087139
2024年4月13日发(作者:general怎么读英语)
js 中 字符串的方法
## JavaScript String Methods.
Strings are a fundamental data type in JavaScript and
they come with a wide range of built-in methods that allow
you to perform various operations on them. Here are some of
the most commonly used string methods:
`length`: Returns the length of the string.
`charAt(index)`: Returns the character at the specified
index in the string.
`charCodeAt(index)`: Returns the Unicode code point of
the character at the specified index in the string.
`indexOf(substring, startIndex)`: Returns the index of
the first occurrence of the specified substring in the
string, starting from the specified start index.
`lastIndexOf(substring, startIndex)`: Returns the index
of the last occurrence of the specified substring in the
string, starting from the specified start index.
`slice(start, end)`: Returns a new string that contains
a portion of the original string, starting at the specified
start index and ending at the specified end index.
`substring(start, end)`: Similar to `slice`, but it
does not accept negative indices.
`substr(start, length)`: Returns a new string that
contains a portion of the original string, starting at the
specified start index and continuing for the specified
length.
`replace(substring, newSubstring)`: Returns a new
string that replaces all occurrences of the specified
substring with the specified new substring.
`toUpperCase()`: Returns a new string that contains the
original string converted to uppercase.
版权声明:本文标题:js 中 字符串的方法 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://roclinux.cn/b/1713018763a617457.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论