I am encountering some challenges while trying to create a new array from existing Objects. If I execute the following code snippet:
console.log(JSON.stringify(this.data))
The output is as follows:
{
"nodes":[
{"id":1,"node":"0","name":"pizza","created_at":"2019-09-01 09:56:01","updated_at":"2019-09-01 09:56:01"},
{"id":2,"node":"1","name":"pasta","created_at":"2019-09-01 09:56:01","updated_at":"2019-09-01 09:56:01"},
{"id":3,"node":"2","name":"pie","created_at":"2019-09-01 09:56:01","updated_at":"2019-09-01 09:56:01"}
],
"links":[
{"id":1,"source":"0","target":"1","value":"451","created_at":"2019-09-01 09:56:01","updated_at":"2019-09-01 09:56:01"},
{"id":2,"source":"1","target":"3","value":"237","created_at":"2019-09-01 09:56:01","updated_at":"2019-09-01 09:56:01"}
]
}
My objective is to extract only the 'node' and 'name' properties from the nodes array, and 'source', 'target', and 'value' properties from the links array. I have attempted various methods without success, such as:
const valuesToRemove = ['id', 'created_at', 'updated_at'];
this.data.links = this.data.links.filter((i) => (valuesToRemove.indexOf(i) === -1));
How can I achieve the desired result similar to the following structure?
{
"nodes":[
{"node":"0","name":"pizza"},
{"node":"1","name":"pasta"},
{"node":"2","name":"pie"}
],
"links":[
{"source":"0","target":"1","value":"451"},
{"source":"1","target":"3","value":"237"}
]
}
Thank you.