String.prototype
String.prototype
属性表示String
原型对象。
| String.prototype
属性的属性特性: |
|:----|
| Writable | no |
| Enumerable | no |
| Configurable | no |
描述
属性
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.trimLeft()
从字符串的左侧去除空格。
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">
(link to URL)String.prototype.small()
<small>
String.prototype.strike()
<strike>
String.prototype.sub()
<sub>
String.prototype.sup()
<sup>
规范
Specification | Status | Comment |
---|---|---|
ECMAScript 1st Edition (ECMA-262) | Standard | Initial definition. |
ECMAScript 5.1 (ECMA-262)The definition of 'String.prototype' in that specification. | Standard | |
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'String.prototype' in that specification. | Standard | |
ECMAScript Latest Draft (ECMA-262)The definition of 'String.prototype' in that specification. | Living Standard | |
浏览器兼容性
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic Support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic Support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com