Read data from JSON array

That explains the issue. In such case test this code inside the function node. It will fetch the timestamp inside payload.data

let today = new Date().toDateString();


let extractor = function (elem) {
    let extr = new Date(elem.payload.data.timestamp).toDateString();
    return extr == today;
}
    
let output1 = msg.payload.filter(extractor);

let output2 = output1.sort(function (a, b) {
    let atime = new Date(a.payload.data.timestamp);
    let btime = new Date(b.payload.data.timestamp);
  return atime-btime;
});

let last = output2.pop();

node.warn(last);
msg.payload =last;

return msg;
1 Like