Array - last (n) item

Hi,
I have a file txt with the min / max temperature for each day and with this code ...

const x = msg.payload;

x.forEach(element => {

    let data
    let tempMin
    let tempMax

    msg.payload = (element.col1)
    data = msg.payload.substr(0, 2)
    
    msg.payload = (element.col1)
    tempMin = msg.payload.substr(6, 4)

    tempMax = (element.col2)

    let arrayData = []   
    let arrayTempMin = []
    let arrayTempMax = []
    
    arrayData = flow.get('valueData') || []
    arrayTempMin = flow.get('valueTempMin') || []
    arrayTempMax = flow.get('valueTempMax') || []
        
    arrayData.push(data)
    arrayTempMin.push(tempMin)
    arrayTempMax.push(tempMax)
    
    flow.set("valueData", arrayData)
    flow.set("valueTempMin", arrayTempMin)
    flow.set("valueTempMax", arrayTempMax)
    
});

return msg;

(where x is the data from txt file), I set 3 array and send the value to a chart and it's works fine......
but the txt file has more 100 row and I'd like to select only the last 30 row.
It's all the morning I try to set this filter without success, can you help me?

(I found how to select the last item, but not the last (n) item ....)

const x = msg.payload.slice(-30);
should return the last 30 indices.

1 Like

Thank you @E1cid, thank you very much ....

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.