TypedArray.prototype.join()

TypedArray 实例的 join() 方法通过连接此类型化数组中的所有元素(用逗号或指定的分隔符字符串分隔)来创建并返回一个新字符串。如果类型化数组只有一项,则将返回该项而不使用分隔符。该方法与 Array.prototype.join() 的算法相同。

¥The join() method of TypedArray instances creates and returns a new string by concatenating all of the elements in this typed array, separated by commas or a specified separator string. If the typed array has only one item, then that item will be returned without using the separator. This method has the same algorithm as Array.prototype.join().

Try it

语法

¥Syntax

js
join()
join(separator)

参数

¥Parameters

separator Optional

用于分隔类型化数组的每对相邻元素的字符串。如果省略,则类型化数组元素用逗号 (",") 分隔。

返回值

¥Return value

连接所有类型化数组元素的字符串。如果 array.length0,则返回空字符串。

¥A string with all typed array elements joined. If array.length is 0, the empty string is returned.

描述

¥Description

详细信息请参见 Array.prototype.join()。此方法不是通用的,只能在类型化数组实例上调用。

¥See Array.prototype.join() for more details. This method is not generic and can only be called on typed array instances.

示例

¥Examples

使用 join()

¥Using join()

js
const uint8 = new Uint8Array([1, 2, 3]);
uint8.join(); // '1,2,3'
uint8.join(" / "); // '1 / 2 / 3'
uint8.join(""); // '123'

规范

Specification
ECMAScript Language Specification
# sec-%typedarray%.prototype.join

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看