The current data structure I am handling:
this.currentData = [
{
"1304": {
"id": 6458,
"data": "Data1",
"created_at": "2020-10-20 23:16:38",
"updated_at": "2020-10-20 23:16:38"
},
"1305": {
"id": 6463,
"data": "Data4",
"created_at": "2020-10-20 23:16:38",
"updated_at": "2020-10-20 23:16:38"
}
}
]
Desired data structure output:
this.desiredData = [
{
"1304": {
"id": 6458,
"data": "Data1",
"created_at": "2020-10-20 23:16:38",
"updated_at": "2020-10-20 23:16:38"
},
"1305": {
"id": 6463,
"data": "Data4",
"created_at"": "2020-10-20 23:16:38",
"updated_at"": "2020-10-20 23:16:38"
}
}
]
In essence, the initial array contains two objects with nested objects (this.currentData).
To achieve the desired outcome, I need to extract specific elements from this.currentData based on a predefined list of numbers. For example, if arrayOfNumbers = [1304, 1305], I want to dynamically filter through the data and retrieve objects associated with these key indices.
The filtering process should be dynamic using variables like arrayOfNumbers which can be generated programmatically as shown in the code below:
this.filterArray = this.someObject.columns.map(Number);
Is there a method to accomplish this and generate the desired output without hardcoding values?
Refer to the end of the code snippet for the target data structure called this.desiredData