I have 2 arrays structured like this :
VM.dataTotalList = result.map(item => {
return {
idEquipment : item['0'],
timestamp : item['1'],
value : item['2']
};
});
VM.dataFreeList = result.map(item => {
return {
idEquipment : item['0'],
timestamp : item['1'],
value : item['2']
};
});
I am interested in extracting only the 'value' property from both arrays. I would like to end up with an array of the same format as a result. Could someone please guide me on how to achieve this?
Thank you!
UPDATE1
VM.dataFreeList = [];
VM.dataTotalList = [];
/**
* Retrieving the total swap value of an idequipment
* */
SwapDataService.getSwapTotalDataList().then((result) => {
// renaming properties in the data array
VM.dataTotalList = result.map(item => {
return {
idEquipment : item['0'],
timestamp : item['1'],
value : parseInt(item['2'])
};
});
}).then(() => {
});
/**
* Retrieving the free swap value of an idequipment
* */
SwapDataService.getSwapFreeDataList().then((result) => {
// renaming properties in the data array
VM.dataFreeList = result.map(item => {
return {
idEquipment : item['0'],
timestamp : item['1'],
value : parseInt(item['2'])
};
});
$log.info('total', VM.dataTotalList);
$log.info('free', VM.dataFreeList);
VM.newdataList = VM.dataTotalList.map((item, index) => {
item['value'] -= VM.dataFreeList[index]['value'];
return item;
});
$log.info('new array', VM.newdataList);
});
Here's a glimpse of the data:
total
(18) […]
0: Object { idEquipment: "b827eb008bb1", timestamp: 1597948232825, value: 256, … }
1: Object { idEquipment: "b827ebb4ceff", timestamp: 1597948294797, value: 0, … }
free
(17) […]
0: Object { idEquipment: "b827eb7945bd", timestamp: 1597948315924, value: 102140, … }
1: Object { idEquipment: "b827eb519c39", timestamp: 1597947610314, value: 102396, … }
2: Object { idEquipment: "b827eb28ab09", timestamp: 1597947933909, value: 100604, … }
And the resulting new array is:
new array
(18) […]
0: Object { idEquipment: "b827ebb4ceff", timestamp: 1597948294797, value: 0, … }
1: Object { idEquipment: "b827eba1e021", timestamp: 1597948154016, value: 768, … }
2: Object { idEquipment: "b827eb15ff2c", timestamp: 1597947773103, value: 1792, … }