Here is the JSON data I have:
{
"list": [
{
"deviceId": "2a-d539-4031-9bfc-4a42f2f765cf",
"versions": [
{
"id": "764c20-a213-9235f4b553b3",
"createdTime": 1590361208034,
"files": [
{
"fileType": "VLAN"
},
{
"fileType": "STARTUPCONFIG",
}
],
"startupRunningStatus": "OUT_OF_SYNC",
"createdBy": "SCHEDULED"
},
{
"id": "9bd33-a45a-ed2fefc46931",
"createdTime": 1589972337717,
"files": [
{
"fileType": "VLAN",
},
{
"fileType": "STARTUPCONFIG",
},
{
"fileType": "RUNNINGCONFIG",
}
],
"startupRunningStatus": "IN_SYNC",
"createdBy": "SCHEDULED_FIRST_TIME"
}
]
}
]
}
I am looking to filter the data where "fileType": "RUNNINGCONFIG" and "fileType": "STARTUPCONFIG" are present inside the 'files' array, and only return that specific array.
For example, from the JSON above, only the second object will be returned.
I attempted to write some filter code for this purpose, but it is not functioning correctly. Can you please guide me?
let versionsData = response.data.versions;
versionsData = versionsData.filter(
versions => {
versions.files.filter(
m => {
return m.fileType === "RUNNINGCONFIG"
}
)
}
);
return versionsData;