String
对象用于表示和操纵字符序列。
字符串对于可以以文本形式表示保持的数据是有用的。最常用的一些字符串操作是校验其
length
,要构建和串联它们使用
+ 和 += 字符串运算符
,检查子字符串的存在或位置采用
indexOf()
方法,或提取子字符串采用
substring()
方法。
可以把字符串创建作为原语,从字符串文字或作为对象,使用
String()
构造函数:
const string1 = "A string primitive"; const string2 = 'Also a string primitive'; const string3 = `Yet another string primitive`;
const string4 = new String("A String object");
String primitives and string objects can be used interchangeably in most situations. See " 字符串原语和字符串对象 " below.
String literals can be specified using single or double quotes, which are treated identically, or using the backtick character ` . This last form specifies a template literal : with this form you can interpolate expressions.
There are two ways to access an individual character in a string. The first is the
charAt()
method:
return 'cat'.charAt(1) // returns "a"
The other way (introduced in ECMAScript 5) is to treat the string as an array-like object, where individual characters correspond to a numerical index:
return 'cat'[1] // returns "a"
When using bracket notation for character access, attempting to delete or assign a value to these properties will not succeed. The properties involved are neither writable nor configurable. (See
Object.defineProperty()
for more information.)
In C, the
strcmp()
function is used for comparing strings. In JavaScript, you just use the
less-than and greater-than operators
:
let a = 'a'
let b = 'b'
if (a < b) { // true
console.log(a + ' is less than ' + b)
} else if (a > b) {
console.log(a + ' is greater than ' + b)
} else {
console.log(a + ' and ' + b + ' are equal.')
}
A similar result can be achieved using the
localeCompare()
method inherited by
String
实例。
注意,
a == b
compares the strings in
a
and
b
for being equal in the usual case-sensitive way. If you wish to compare without regard to upper or lower case characters, use a function similar to this:
function isEqual(str1, str2)
{
return str1.toUpperCase() === str2.toUpperCase()
} // isEqual
Upper case is used instead of lower case in this function, due to problems with certain UTF-8 character conversions.
注意,JavaScript 区分
String
对象和
原语字符串
值。(如同 true 的
布尔
and
数字
.)
String literals (denoted by double or single quotes) and strings returned from
String
calls in a non-constructor context (that is, called without using the
new
keyword) are primitive strings. JavaScript automatically converts primitives to
String
objects, so that it's possible to use
String
object methods for primitive strings. In contexts where a method is to be invoked on a primitive string or a property lookup occurs, JavaScript will automatically wrap the string primitive and call the method or perform the property lookup.
let s_prim = 'foo' let s_obj = new String(s_prim) console.log(typeof s_prim) // Logs "string" console.log(typeof s_obj) // Logs "object"
字符串原语和
String
objects also give different results when using
eval()
. Primitives passed to
eval
are treated as source code;
String
objects are treated as all other objects are, by returning the object. For example:
let s1 = '2 + 2' // creates a string primitive
let s2 = new String('2 + 2') // creates a String object
console.log(eval(s1)) // returns the number 4
console.log(eval(s2)) // returns the string "2 + 2"
For these reasons, the code may break when it encounters
String
objects when it expects a primitive string instead, although generally, authors need not worry about the distinction.
A
String
object can always be converted to its primitive counterpart with the
valueOf()
方法。
console.log(eval(s2.valueOf())) // returns the number 4
可以使用转义表示法编码特殊字符:
| 代码 | 输出 |
|---|---|
\
XXX
(where
XXX
is 1–3 octal digits; range of
0
–
377
)
|
ISO-8859-1 character / Unicode code point between
U+0000
and
U+00FF
|
\'
|
单引号 |
\"
|
双引号 |
\\
|
backslash |
\n
|
换行 |
\r
|
CR (回车) |
\v
|
vertical tab |
\t
|
tab |
\b
|
backspace |
\f
|
换页 |
\u
XXXX
(where
XXXX
is 4 hex digits; range of
0x0000
–
0xFFFF
)
|
UTF-16 code unit / Unicode code point between
U+0000
and
U+FFFF
|
\u{
X
}
...
\u{
XXXXXX
}
(where
X
…
XXXXXX
is 1–6 hex digits; range of
0x0
–
0x10FFFF
)
|
UTF-32 code unit / Unicode code point between
U+0000
and
U+10FFFF
|
\x
XX
(where
XX
is 2 hex digits; range of
0x00
–
0xFF
)
|
ISO-8859-1 character / Unicode code point between
U+0000
and
U+00FF
|
Sometimes, your code will include strings which are very long. Rather than having lines that go on endlessly, or wrap at the whim of your editor, you may wish to specifically break the string into multiple lines in the source code without affecting the actual string contents. There are two ways you can do this.
可以使用 + 运算符把多个字符串追加到一起,像这样:
let longString = "This is a very long string which needs " +
"to wrap across multiple lines because " +
"otherwise my code is unreadable."
可以使用反斜杠字符 (
\
) at the end of each line to indicate that the string will continue on the next line. Make sure there is no space or any other character after the backslash (except for a line break), or as an indent; otherwise it will not work.
That form looks like this:
let longString = "This is a very long string which needs \ to wrap across multiple lines because \ otherwise my code is unreadable."
Both of the above methods result in identical strings.
String()
String
object. It performs type conversion when called as a function, rather than as a constructor, which is usually more useful.
String.fromCharCode(
num1
[, ...[,
numN
]])
Returns a string created by using the specified sequence of Unicode values.
String.fromCodePoint(
num1
[, ...[,
numN
)
Returns a string created by using the specified sequence of code points.
String.raw()
Returns a string created from a raw template string.
String.prototype.length
length
对于字符串。只读。
String.prototype.charAt(
index
)
index
.
String.prototype.charCodeAt(
index
)
index
.
String.prototype.codePointAt(
pos
)
pos
.
String.prototype.concat(
str
[, ...
strN
])
Combines the text of two (or more) strings and returns a new string.
String.prototype.includes(
searchString
[,
position
])
searchString
.
String.prototype.endsWith(
searchString
[,
length
])
searchString
.
String.prototype.indexOf(
searchValue
[,
fromIndex
])
String
object of the first occurrence of
searchValue
,或
-1
若找不到。
String.prototype.lastIndexOf(
searchValue
[,
fromIndex
])
String
object of the last occurrence of
searchValue
,或
-1
若找不到。
String.prototype.localeCompare(
compareString
[,
locales
[,
options
]])
compareString
comes before, after, or is equivalent to the given string in sort order.
String.prototype.match(
regexp
)
regexp
与字符串。
String.prototype.matchAll(
regexp
)
regexp
's matches.
String.prototype.normalize([
form
])
Returns the Unicode Normalization Form of the calling string value.
String.prototype.padEnd(
targetLength
[,
padString
])
targetLength
.
String.prototype.padStart(
targetLength
[,
padString
])
targetLength
.
String.prototype.repeat(
count
)
count
times.
String.prototype.replace(
searchFor
,
replaceWith
)
searchFor
使用
replaceWith
.
searchFor
may be a string or Regular Expression, and
replaceWith
可以是字符串 (或函数)。
String.prototype.replaceAll(
searchFor
,
replaceWith
)
searchFor
使用
replaceWith
.
searchFor
may be a string or Regular Expression, and
replaceWith
可以是字符串 (或函数)。
String.prototype.search(
regexp
)
regexp
and the calling string.
String.prototype.slice(
beginIndex
[,
endIndex
])
Extracts a section of a string and returns a new string.
String.prototype.split([
sep
[,
limit
] ])
sep
.
String.prototype.startsWith(
searchString
[,
length
])
searchString
.
String.prototype.substr()
返回从指定位置开始到指定字符数的字符串中的字符。
String.prototype.substring(
indexStart
[,
indexEnd
])
Returns a new string containing characters of the calling string from (or between) the specified index (or indeces).
String.prototype.toLocaleLowerCase( [
locale
, ...
locales
])
The characters within a string are converted to lowercase while respecting the current locale.
For most languages, this will return the same as
toLowerCase()
.
String.prototype.toLocaleUpperCase( [
locale
, ...
locales
])
The characters within a string are converted to uppercase while respecting the current locale.
For most languages, this will return the same as
toUpperCase()
.
String.prototype.toLowerCase()
Returns the calling string value converted to lowercase.
String.prototype.toString()
Object.prototype.toString()
方法。
String.prototype.toUpperCase()
返回被转换为大写的调用字符串值。
String.prototype.trim()
Trims whitespace from the beginning and end of the string. Part of the ECMAScript 5 standard.
String.prototype.trimStart()
Trims whitespace from the beginning of the string.
String.prototype.trimEnd()
从字符串末尾开始修剪空白。
String.prototype.valueOf()
Object.prototype.valueOf()
方法。
String.prototype.@@iterator()
Iterator
object that iterates over the code points of a String value, returning each code point as a String value.
弃用。避免这些方法。
它们用途有限,因为它们仅提供可用 HTML 标签和属性的子集。
String.prototype.anchor()
<a name="name">
(超文本目标)
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">
(链接到 URL)
String.prototype.small()
<small>
String.prototype.strike()
<strike>
String.prototype.sub()
<sub>
String.prototype.sup()
<sup>
它是可能的使用
String
作为更可靠的
toString()
alternative, as it works when used on
null
,
undefined
, and on
symbols
。例如:
let outputStrings = []
for (let i = 0, n = inputValues.length; i < n; ++i) {
outputStrings.push(String(inputValues[i]));
}
| 规范 |
|---|
|
ECMAScript (ECMA-262)
在该规范中的 String 定义。 |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
String
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
String()
构造函数
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
anchor
弃用
|
Chrome 1 | Edge 12 |
Firefox
1
|
IE No | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
big
弃用
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
blink
弃用
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
bold
弃用
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
charAt
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
charCodeAt
|
Chrome 1 | Edge 12 | Firefox 1 | IE 4 | Opera 4 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
codePointAt
|
Chrome 41 | Edge 12 | Firefox 29 | IE No | Opera 28 | Safari 10 | WebView Android 41 | Chrome Android 41 | Firefox Android 29 | Opera Android 28 | Safari iOS 10 | Samsung Internet Android 4.0 |
nodejs
4.0.0
|
concat
|
Chrome 1 | Edge 12 | Firefox 1 | IE 4 | Opera 4 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
endsWith
|
Chrome 41 | Edge 12 | Firefox 17 | IE No | Opera 28 | Safari 9 | WebView Android ≤37 | Chrome Android 36 | Firefox Android 17 | Opera Android 24 | Safari iOS 9 | Samsung Internet Android 3.0 |
nodejs
4.0.0
|
fixed
弃用
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
fontcolor
弃用
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
fontsize
弃用
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
fromCharCode
|
Chrome 1 | Edge 12 | Firefox 1 | IE 4 | Opera 4 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
fromCodePoint
|
Chrome 41 | Edge 12 | Firefox 29 | IE No | Opera 28 | Safari 10 | WebView Android 41 | Chrome Android 41 | Firefox Android 29 | Opera Android 28 | Safari iOS 10 | Samsung Internet Android 4.0 |
nodejs
4.0.0
|
includes
|
Chrome 41 | Edge 12 |
Firefox
40
|
IE No | Opera 28 | Safari 9 | WebView Android 41 | Chrome Android 41 |
Firefox Android
40
|
Opera Android 28 | Safari iOS 9 | Samsung Internet Android 4.0 | nodejs 4.0.0 |
indexOf
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
italics
弃用
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
lastIndexOf
|
Chrome 1 | Edge 12 | Firefox 1 | IE 6 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
length
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
link
弃用
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
localeCompare
|
Chrome 1 | Edge 12 | Firefox 1 | IE 5.5 | Opera 7 | Safari 3 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
match
|
Chrome 1 | Edge 12 | Firefox 1 | IE 4 | Opera 4 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
matchAll
|
Chrome 73 | Edge 79 | Firefox 67 | IE No | Opera 60 | Safari 13 | WebView Android 73 | Chrome Android 73 | Firefox Android 67 | Opera Android 52 | Safari iOS 13 | Samsung Internet Android No | nodejs 12.0.0 |
normalize
|
Chrome 34 | Edge 12 | Firefox 31 | IE No | Opera 21 | Safari 10 | WebView Android No | Chrome Android 34 | Firefox Android 31 | Opera Android 21 | Safari iOS 10 | Samsung Internet Android 2.0 | nodejs 0.12 |
padEnd
|
Chrome 57 | Edge 15 | Firefox 48 | IE No | Opera 44 | Safari 10 | WebView Android 57 | Chrome Android 57 | Firefox Android 48 | Opera Android 43 | Safari iOS 10 | Samsung Internet Android 7.0 |
nodejs
8.0.0
|
padStart
|
Chrome 57 | Edge 15 | Firefox 48 | IE No | Opera 44 | Safari 10 | WebView Android 57 | Chrome Android 57 | Firefox Android 48 | Opera Android 43 | Safari iOS 10 | Samsung Internet Android 7.0 |
nodejs
8.0.0
|
raw
|
Chrome 41 | Edge 12 | Firefox 34 | IE No | Opera No | Safari 10 | WebView Android No | Chrome Android 41 | Firefox Android 34 | Opera Android No | Safari iOS 10 | Samsung Internet Android 4.0 | nodejs 4.0.0 |
repeat
|
Chrome 41 | Edge 12 | Firefox 24 | IE No | Opera 28 | Safari 9 | WebView Android No | Chrome Android 36 | Firefox Android 24 | Opera Android 28 | Safari iOS 9 | Samsung Internet Android 3.0 |
nodejs
4.0.0
|
replace
|
Chrome 1 | Edge 12 | Firefox 1 | IE 4 | Opera 4 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
replaceAll
|
Chrome 85 | Edge No | Firefox 77 | IE No | Opera No | Safari 13.1 | WebView Android 85 | Chrome Android 85 | Firefox Android No | Opera Android No | Safari iOS 13.4 | Samsung Internet Android No | nodejs No |
search
|
Chrome 1 | Edge 12 | Firefox 1 | IE 4 | Opera 4 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
slice
|
Chrome 1 | Edge 12 | Firefox 1 | IE 4 | Opera 4 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
small
弃用
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
split
|
Chrome 1 | Edge 12 | Firefox 1 | IE 4 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
startsWith
|
Chrome 41 | Edge 12 | Firefox 17 | IE No | Opera 28 | Safari 9 | WebView Android ≤37 | Chrome Android 36 | Firefox Android 17 | Opera Android 24 | Safari iOS 9 | Samsung Internet Android 3.0 |
nodejs
4.0.0
|
strike
弃用
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
sub
弃用
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
substr
弃用
|
Chrome 1 | Edge 12 | Firefox 1 | IE 4 | Opera 4 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
substring
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
sup
弃用
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
toLocaleLowerCase
|
Chrome 1 | Edge 12 | Firefox 1 | IE 5.5 | Opera 4 | Safari 1.3 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
toLocaleUpperCase
|
Chrome 1 | Edge 12 | Firefox 1 | IE 5.5 | Opera 4 | Safari 1.3 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
toLowerCase
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
toSource
非标
|
Chrome No | Edge No |
Firefox
1 — 74
|
IE No | Opera No | Safari No | WebView Android No | Chrome Android No | Firefox Android 4 | Opera Android No | Safari iOS No | Samsung Internet Android No | nodejs No |
toString
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
toUpperCase
|
Chrome 1 | Edge 12 | Firefox 1 | IE 3 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
trim
|
Chrome 4 | Edge 12 | Firefox 3.5 | IE 9 | Opera 10.5 | Safari 5 | WebView Android ≤37 | Chrome Android 18 | Firefox Android 4 | Opera Android 11 | Safari iOS 5 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
trimEnd
|
Chrome
66
|
Edge
12
Alternate Name
|
Firefox
61
|
IE No |
Opera
53
|
Safari 12 |
WebView Android
66
|
Chrome Android
66
|
Firefox Android
61
|
Opera Android
47
|
Safari iOS 12 |
Samsung Internet Android
9.0
|
nodejs
10.0.0
|
trimStart
|
Chrome
66
|
Edge
12
Alternate Name
|
Firefox
61
|
IE No |
Opera
53
|
Safari 12 |
WebView Android
66
|
Chrome Android
66
|
Firefox Android
61
|
Opera Android
47
|
Safari iOS 12 |
Samsung Internet Android
9.0
|
nodejs
10.0.0
|
| Unicode code point escapes \u{xxxxxx} | Chrome 1 | Edge 12 | Firefox 40 | IE 4 | Opera 4 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 40 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
valueOf
|
Chrome 1 | Edge 12 | Firefox 1 | IE 4 | Opera 3 | Safari 1 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs 0.1.100 |
@@iterator
|
Chrome 38 | Edge 12 |
Firefox
36
|
IE No | Opera 25 | Safari No | WebView Android 38 | Chrome Android 38 |
Firefox Android
36
|
Opera Android 25 | Safari iOS No | Samsung Internet Android 3.0 | nodejs 0.12 |
完整支持
不支持
非标。预期跨浏览器支持较差。
弃用。不要用于新网站。
见实现注意事项。
用户必须明确启用此特征。
使用非标名称。
String
String.fromCharCode()
String.fromCodePoint()
String.prototype.anchor()
String.prototype.big()
String.prototype.blink()
String.prototype.bold()
String.prototype.charAt()
String.prototype.charCodeAt()
String.prototype.codePointAt()
String.prototype.concat()
String.prototype.endsWith()
String.prototype.fixed()
String.prototype.fontcolor()
String.prototype.fontsize()
String.prototype.includes()
String.prototype.indexOf()
String.prototype.italics()
String.prototype.lastIndexOf()
String.prototype.link()
String.prototype.localeCompare()
String.prototype.match()
String.prototype.matchAll()
String.prototype.normalize()
String.prototype.padEnd()
String.prototype.padStart()
String.prototype.repeat()
String.prototype.replace()
String.prototype.replaceAll()
String.prototype.search()
String.prototype.slice()
String.prototype.small()
String.prototype.split()
String.prototype.startsWith()
String.prototype.strike()
String.prototype.sub()
String.prototype.substr()
String.prototype.substring()
String.prototype.sup()
String.prototype.toLocaleLowerCase()
String.prototype.toLocaleUpperCase()
String.prototype.toLowerCase()
String.prototype.toSource()
String.prototype.toString()
String.prototype.toUpperCase()
String.prototype.trim()
String.prototype.trimEnd()
String.prototype.trimStart()
String.prototype.valueOf()
String.prototype[@@iterator]()
String.raw()
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()