i have a array which looks like this :
[
{
"1": {
"id": 1,
"price": 569.2,
"marketcap": 94943213384.68,
"timestamp": 1637136047,
"datetime": "2021-11-17 08:00:47"
},
"2": {
"id": 2,
"price": 59745.7,
"marketcap": 1127634159487.02,
"timestamp": 1637136064,
"datetime": "2021-11-17 08:01:04"
},
"3": {
"id": 3,
"price": 592.53,
"marketcap": 11199494644.95126,
"timestamp": 1637136053,
"datetime": "2021-11-17 08:00:53"
}
},
{
"1": {
"id": 1,
"last30dcommits": null,
"activity": "No Github Repo Found"
},
"2": {
"id": 2,
"last30dcommits": 109,
"activity": "High Activity"
},
"3": {
"id": 3,
"last30dcommits": 44,
"activity": "Medium Activity"
}
},
{
"1": {
"id": 1,
"change24h": -6.75,
"change7d": -10.18,
"change30d": 17.32,
"timestamp24h": 1637035200,
"timestamp7d": 1636516800,
"timestamp30d": 1634529600
},
"2": {
"id": 2,
"change24h": -3.22,
"change7d": -12.58,
"change30d": -5.17,
"timestamp24h": 1637035200,
"timestamp7d": 1636516800,
"timestamp30d": 1634529600
},
"3": {
"id": 3,
"change24h": -6.37,
"change7d": -17.81,
"change30d": -5.04,
"timestamp24h": 1637035200,
"timestamp7d": 1636516800,
"timestamp30d": 1634529600
}
},
{
"1": {
"tweetsRating": 44.04,
"newsRating": 38.42
},
"2": {
"tweetsRating": 14.76,
"newsRating": -1.27
},
"3": {
"tweetsRating": 0,
"newsRating": 44.35
}
},
]
I am implementing a pagination in the front end in which I am slicing each objects in each object in the array to a given value so that I get a result something like this if I slice (0,2)
[
{
"1": {
"id": 1,
"price": 569.2,
"marketcap": 94943213384.68,
"timestamp": 1637136047,
"datetime": "2021-11-17 08:00:47"
},
"2": {
"id": 2,
"price": 59745.7,
"marketcap": 1127634159487.02,
"timestamp": 1637136064,
"datetime": "2021-11-17 08:01:04"
}
},
{
"1": {
"id": 1,
"last30dcommits": null,
"activity": "No Github Repo Found"
},
"2": {
"id": 2,
"last30dcommits": 109,
"activity": "High Activity"
}
},
{
"1": {
"id": 1,
"change24h": -6.75,
"change7d": -10.18,
"change30d": 17.32,
"timestamp24h": 1637035200,
"timestamp7d": 1636516800,
"timestamp30d": 1634529600
},
"2": {
"id": 2,
"change24h": -3.22,
"change7d": -12.58,
"change30d": -5.17,
"timestamp24h": 1637035200,
"timestamp7d": 1636516800,
"timestamp30d": 1634529600
}
},
{
"1": {
"tweetsRating": 44.04,
"newsRating": 38.42
},
"2": {
"tweetsRating": 14.76,
"newsRating": -1.27
}
},
]
means only 2 objects should be sliced out. my function is as following but its not working.
const sliceData = (array,start,end)=>{
array.forEach(arr=>{
Object.keys(arr).slice(start - 1, end + 1).reduce((result, key) => {
result[key] = arr[key];
return result;
}
})
}
Here start and end represents the index of starting object in a page and index of last object in the page respectively. Can anyone help me with the code? I'll be very grateful.