toString()
method returns a string representing the specified array and its elements. This method has the same algorithm as
Array.prototype.toString()
.
TypedArray
is one of the
typed array types
here.
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
typedarray.toString()
A string representing the elements of the typed array.
TypedArray
objects override the
toString
方法为
Object
. For TypedArray objects, the
toString
method joins the array and returns one string containing each typed array element separated by commas. For example, the following code creates a typed array and uses
toString
to convert the array to a string.
var numbers = new Uint8Array([2, 5, 8, 1, 4]) numbers.toString(); // "2,5,8,1,4"
JavaScript calls the
toString
method automatically when a typed array is to be represented as a text value or when an array is referred to in a string concatenation.
If a browser doesn't support the
TypedArray.prototype.toString()
method yet, JavaScript will call the
toString
方法为
Object
:
var numbers = new Uint8Array([2, 5, 8, 1, 4]) numbers.toString(); // "[object Uint8Array]"
| 规范 |
|---|
|
ECMAScript (ECMA-262)
The definition of 'Array.prototype.toString' in that specification. |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
toString
|
Chrome 7 | Edge 12 | Firefox 51 | IE 10 | Opera 11.6 | Safari 5.1 | WebView Android ≤37 | Chrome Android 18 | Firefox Android 51 | Opera Android 12 | Safari iOS 5 | Samsung Internet Android 1.0 | nodejs 0.10 |
完整支持
TypedArray
TypedArray.from()
TypedArray.of()
TypedArray.prototype.copyWithin()
TypedArray.prototype.entries()
TypedArray.prototype.every()
TypedArray.prototype.fill()
TypedArray.prototype.filter()
TypedArray.prototype.find()
TypedArray.prototype.findIndex()
TypedArray.prototype.forEach()
TypedArray.prototype.includes()
TypedArray.prototype.indexOf()
TypedArray.prototype.join()
TypedArray.prototype.keys()
TypedArray.prototype.lastIndexOf()
TypedArray.prototype.map()
TypedArray.prototype.reduce()
TypedArray.prototype.reduceRight()
TypedArray.prototype.reverse()
TypedArray.prototype.set()
TypedArray.prototype.slice()
TypedArray.prototype.some()
TypedArray.prototype.sort()
TypedArray.prototype.subarray()
TypedArray.prototype.toLocaleString()
TypedArray.prototype.toString()
TypedArray.prototype.values()
TypedArray.prototype[@@iterator]()
Int8Array
Uint8Array
Uint8ClampedArray
Int16Array
Uint16Array
Int32Array
Uint32Array
Float32Array
Float64Array
BigInt64Array
BigUint64Array
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()