I have this array of objects that I retrieved from an API. It is continuously being updated everyday. The array consists of a timeseries of cases for everyday. I want to use this array to return the cases for each date for the last week. I have fetched the country name and filtered the array, so it only shows the user's country's array. I was thinking I can map across the dates of the array to find the last 7 indexes. Is there a way to do this?
useEffect(() => {
axios
.get("https://api.covid19india.org/v4/min/timeseries.min.json")
.then((response) => {
setEarliest2(response.data);
const stateArray = response.data.filter(
(item) => item.country === mappedLocation.stateShort
);
}
{
"AN": {
"dates": {
"2020-03-26": {
"delta": {
"confirmed": 1
},
"delta7": {
"confirmed": 1
},
"total": {
"confirmed": 1
}
},
"2020-03-27": {
"delta": {
"confirmed": 5
},
"delta7": {
"confirmed": 6
},
"total": {
"confirmed": 6
}
},
"2020-03-28": {
"delta": {
"confirmed": 3
},
"delta7": {
"confirmed": 9
},
"total": {
"confirmed": 9
}
},
"2020-03-29": {
"delta7": {
"confirmed": 9
},
"total": {
"confirmed": 9
}
},
"2020-03-30": {
"delta": {
"confirmed": 1
},
"delta7": {
"confirmed": 10
},
"total": {
"confirmed": 10
}
},
...
}
const DataSet = (props) => {
return [
{
x: new Date(
parseInt(moment().format("YYYY")),
parseInt(moment().format("M")),
parseInt(moment().format("DD")) - 7
),
response.datais an array of objects.typescriptandreact-native?Object.keys()), sort them, get the first/last (depending on the sort order) sevenreact-nativeandtypescript? Otherwise, why would I tag those? Could you provide an example of your answer?response.data.filtersince strings don't have afiltermethod.