String.prototype 属性表示 String原型对象。
String.prototype 属性的属性特性: |
|
|---|---|
| writable | false |
| enumerable | false |
| configurable | false |
描述
所有 String 实例。
属性
-
String.prototype.constructor - 用于创造对象的原型对象的特定的函数。
-
String.prototype.length - 返回了字符串的长度。
- N
-
用于访问第N个位置的字符,其中N是小于
length和 0之间的正整数。这些属性都是“只读”性质,不能编辑。
方法
跟HTML无关的方法
-
String.prototype.charAt() - 返回特定位置的字符。
-
String.prototype.charCodeAt() - 返回表示给定索引的字符的Unicode的值。
-
String.prototype.codePointAt() - 返回使用UTF-16编码的给定位置的值的非负整数。
-
String.prototype.concat() - 连接两个字符串文本,并返回一个新的字符串。
-
String.prototype.includes() - 判断一个字符串里是否包含其他字符串。
-
String.prototype.endsWith() - 判断一个字符串的是否以给定字符串结尾,结果返回布尔值。
-
String.prototype.indexOf() - 从字符串对象中返回首个被发现的给定值的索引值,如果没有找到则返回-1。
-
String.prototype.lastIndexOf() - 从字符串对象中返回最后一个被发现的给定值的索引值,如果没有找到则返回-1。
-
String.prototype.localeCompare() - 返回一个数字表示是否引用字符串在排序中位于比较字符串的前面,后面,或者二者相同。
-
String.prototype.match() - 使用正则表达式与字符串相比较。
-
String.prototype.normalize() - 返回调用字符串值的Unicode标准化形式。
-
String.prototype.padEnd() - 在当前字符串尾部填充指定的字符串, 直到达到指定的长度。 返回一个新的字符串。
-
String.prototype.padStart() -
在当前字符串头部填充指定的字符串, 直到达到指定的长度。 返回一个新的字符串。
-
String.prototype.quote() - 设置嵌入引用的引号类型。
-
String.prototype.repeat() - 返回指定重复次数的由元素组成的字符串对象。
-
String.prototype.replace() - 被用来在正则表达式和字符串直接比较,然后用新的子串来替换被匹配的子串。
-
String.prototype.search() - 对正则表达式和指定字符串进行匹配搜索,返回第一个出现的匹配项的下标。
-
String.prototype.slice() - 摘取一个字符串区域,返回一个新的字符串。
-
String.prototype.split() - 通过分离字符串成字串,将字符串对象分割成字符串数组。
-
String.prototype.startsWith() - 判断字符串的起始位置是否匹配其他字符串中的字符。
-
String.prototype.substr() - 通过指定字符数返回在指定位置开始的字符串中的字符。
-
String.prototype.substring() - 返回在字符串中指定两个下标之间的字符。
-
String.prototype.toLocaleLowerCase() -
根据当前区域设置,将符串中的字符转换成小写。对于大多数语言来说,
toLowerCase的返回值是一致的。 -
String.prototype.toLocaleUpperCase() -
根据当前区域设置,将字符串中的字符转换成大写,对于大多数语言来说,
toUpperCase的返回值是一致的。 -
String.prototype.toLowerCase() - 将字符串转换成小写并返回。
-
String.prototype.toSource() -
返回一个对象文字代表着特定的对象。你可以使用这个返回值来创建新的对象。重写
Object.prototype.toSource方法。 -
String.prototype.toString() -
返回用字符串表示的特定对象。重写
Object.prototype.toString方法。 -
String.prototype.toUpperCase() - 将字符串转换成大写并返回。
-
String.prototype.trim() - 从字符串的开始和结尾去除空格。参照部分 ECMAScript 5 标准。
-
String.prototype.trimStart() -
String.prototype.trimLeft() - 从字符串的左侧去除空格。
-
String.prototype.trimEnd() -
String.prototype.trimRight() - 从字符串的右侧去除空格。
-
String.prototype.valueOf() -
返回特定对象的原始值。重写
Object.prototype.valueOf方法。 -
String.prototype[@@iterator]() - 返回一个新的迭代器对象,该对象遍历字符串值的索引位置,将每个索引值作为字符串值返回。
HTML wrapper methods
下面的方法被限制使用,因为只对可用的HTML标签和属性提供部分支持。
-
String.prototype.anchor() -
<a name="name">(hypertext target) -
String.prototype.big() -
<big> -
String.prototype.blink() -
<blink> -
String.prototype.bold() -
<b> -
String.prototype.fixed() -
<tt> -
String.prototype.fontcolor() -
<font color="color"> -
String.prototype.fontsize() -
<font size="size"> -
String.prototype.italics() -
<i> -
String.prototype.link() -
<a href="url.htm">(link to URL) -
String.prototype.small() -
<small> -
String.prototype.strike() -
<strike> -
String.prototype.sub() -
<sub> -
String.prototype.sup() -
<sup>
Specifications
| 规范 | 状态 | 备注 |
|---|---|---|
| ECMAScript 1st Edition. | Standard | Initial definition. |
| ECMAScript 5.1 (ECMA-262) String.prototype |
Standard | |
| ECMAScript 2015 (6th Edition, ECMA-262) String.prototype |
Standard | |
| ECMAScript Latest Draft (ECMA-262) String.prototype |
Draft |
浏览器兼容性
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
prototype |
Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
Legend
- Full support
- Full support