I'm working on a fuel price monitoring feature for our family website using Node-Red. This tool is aimed at helping the kids keep track of local fuel prices compared to the average, in an effort to save some money when they refuel their cars.
Currently, I am attempting to extract the values from an array by copying the necessary path into a variable like so:
current_price_e5 = payload.stations[0].prices.E5
The 'stations' array consists of over 300 entries and appears to be dynamic in terms of length, each entry containing multiple keys (refer to image below). How can I retrieve all the values for each key under 'prices' across the entire array? The approach mentioned above clearly doesn't work, but it is what I require for a new msg.payload:
current_price_e5 = payload.stations[0-313].prices.E5
https://i.sstatic.net/M0VhZ.jpg
Fortunately, I was able to resolve this issue by following the suggested code snippet. For future reference, the following code worked for me and allowed me to further process the data for averaging, minimum, and maximum calculations:
const e10Prices = msg.payload.stations.map(station =>
station.prices).map(price => price.E10);
msg.payload = e10Prices;
return msg;