TypedArray.prototype.toReversed()

TypedArray 实例的 toReversed() 方法是 reverse() 方法的 copying 对应方法。它返回一个新的类型化数组,其中元素的顺序相反。该方法与 Array.prototype.toReversed() 的算法相同。

¥The toReversed() method of TypedArray instances is the copying counterpart of the reverse() method. It returns a new typed array with the elements in reversed order. This method has the same algorithm as Array.prototype.toReversed().

语法

¥Syntax

js
toReversed()

参数

¥Parameters

没有任何。

¥None.

返回值

¥Return value

包含相反顺序元素的新类型化数组。

¥A new typed array containing the elements in reversed order.

描述

¥Description

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

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

示例

¥Examples

使用 toReversed()

¥Using toReversed()

js
const uint8 = new Uint8Array([1, 2, 3]);
const reversedUint8 = uint8.toReversed();
console.log(reversedUint8); // Uint8Array [3, 2, 1]
console.log(uint8); // Uint8Array [1, 2, 3]

规范

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

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看