JavaScript Array toReversed() Method
Example
Reverses the order of elements in an array:
//
Creating an Array
const
sites
=
[
"
"
,
"
Runoob
"
,
"
JYSHARE
"
,
"
Taobao
"
]
;
//
Reverse the array
const
sites2
=
sites
.
toReversed
(
)
;
document
.
getElementById
(
"
demo
"
)
.
innerHTML
=
sites2
;
Output result:
Taobao,JYSHARE,Runoob,Google
Try it »
Definition and Usage
The toReversed() method is used to reverse the order of elements in an array.
The toReversed() method returns a new array.
The toReversed() method does not modify the original array.
toReversed() is a copy version of the reverse() method.
Browser support
toReversed() is a feature of ES2023.
Since July 2023, all modern browsers support this feature:
| Chrome 110 | Edge 110 | Firefox 115 | Safari 16.4 | Opera 96 |
| Feb 2023 | Feb 2023 | Jul 2023 | Mar 2023 | May 2023 |
Syntax
array.toReversed()
Parameters
| Parameters | Description |
|---|---|
| None | None |
Return Value
| Type | Description |
|---|---|
| Array | Returns a new array with the element order reversed. The value of the last element matching the test condition; if none is found, returns undefined. |
JavaScript Array object