TypedArray.prototype.reverse()

TypedArray 实例的 reverse() 方法反转类型化数组 到位 并返回对同一类型化数组的引用,第一个类型化数组元素现在成为最后一个,最后一个类型化数组元素成为第一个。换句话说,类型化数组中的元素顺序将转向与前面所述相反的方向。该方法与 Array.prototype.reverse() 的算法相同。

¥The reverse() method of TypedArray instances reverses a typed array in place and returns the reference to the same typed array, the first typed array element now becoming the last, and the last typed array element becoming the first. In other words, elements order in the typed array will be turned towards the direction opposite to that previously stated. This method has the same algorithm as Array.prototype.reverse().

Try it

语法

¥Syntax

js
reverse()

参数

¥Parameters

没有任何。

¥None.

返回值

¥Return value

对原始类型化数组的引用,现在已反转。请注意,类型化数组被反转 到位,并且不进行任何复制。

¥The reference to the original typed array, now reversed. Note that the typed array is reversed in place, and no copy is made.

描述

¥Description

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

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

示例

¥Examples

使用反向()

¥Using reverse()

js
const uint8 = new Uint8Array([1, 2, 3]);
uint8.reverse();

console.log(uint8); // Uint8Array [3, 2, 1]

规范

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

¥Specifications

浏览器兼容性

BCD tables only load in the browser

¥Browser compatibility

也可以看看