首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

typedArray.join

join()方法将数组中所有元素连接为一个字符串。这个方法的算法和Array.prototype.join()相同。TypedArray是这里的类型化数组之一。

语法

代码语言:javascript
复制
typedarray.join([separator = ',']);

参数

separator可选。指定分隔每个元素的字符串。分隔符按需转换为字符串。如果没有,类型化数组的元素会以逗号(",")分隔。

返回值

所有元素连接后的字符串。

示例

代码语言:javascript
复制
var uint8 = new Uint8Array([1,2,3]);
uint8.join();      // '1,2,3'
uint8.join(' / '); // '1 / 2 / 3'
uint8.join('');    // '123'

Polyfill

由于没有名为TypedArray的全局元素,polyfill 必须"按情况"实现。

代码语言:javascript
复制
// https://tc39.github.io/ecma262/#sec-%typedarray%.prototype.join
if (!Uint8Array.prototype.join) {
  Object.defineProperty(Uint8Array.prototype, 'join', {
    value: Array.prototype.join
  });
}

如果你需要支持过时的 JavaScript 引擎,它们不支持Object.defineProperty,最好不要 polyfillArray.prototype方法,因为你不能使它们不可枚举。

规范

Specification

Status

Comment

ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'TypedArray.prototype.join' in that specification.

Standard

Initial definition.

ECMAScript 2017 Draft (ECMA-262)The definition of 'TypedArray.prototype.join' in that specification.

Draft

?

浏览器兼容性

Feature

Chrome

Edge

Firefox (Gecko)

Internet Explorer

Opera

Safari

Basic support

(Yes)

(Yes)

37 (37)

No support

No support

No support

Feature

Android

Chrome for Android

Firefox Mobile (Gecko)

IE Mobile

Opera Mobile

Safari Mobile

Basic support

No support

No support

37.0 (37)

No support

No support

No support

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com