Reverse an array java script code example
Example 1: reversing an array in js
var arr=[1,2,5,6,2]
arr.reverse()
Example 2: reverse array javascript
const list = [1, 2, 3, 4, 5];
list.reverse();
Example 3: Reverse an array java script
import React, { Component } from 'react';
export default class Slideshows extends Component {
constructor(){
super();
this.state = {
data:[
{ "id": "1", "name": 'Robert', "age": "21" },
{ "id": "2", "name": 'Sam', "age": "33" },
{ "id": "3", "name": 'Jerry', "age": "42" },
]
}
}
render() {
const reverseData = this.state.map((data, i) => {
return (
<li> {data.name} | {data.age} </li>
)
})
return (
<ul>
{reverseData}
</ul>
)
}
}