[{"id":"e960bce4c7bccaa7","type":"inject","z":"3d8a22efe6ba1aba","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[{\"added_on\":1,\"name\":\"a\",\"hash\":12345},{\"added_on\":7,\"name\":\"b\",\"hash\":54321},{\"added_on\":120,\"name\":\"c\",\"hash\":7777},{\"added_on\":120,\"name\":\"d\",\"hash\":11111}]","payloadType":"json","x":3025.60009765625,"y":2558.800048828125,"wires":[["6fa48b3d59fba989","053ffca12d0307e9"]]},{"id":"6fa48b3d59fba989","type":"function","z":"3d8a22efe6ba1aba","name":"function 28","func":"let start = msg.payload[0].added_on;\nmsg.payload = msg.payload.reduce((acc,obj,index) =>{\n if(obj.added_on > acc.max){\n acc = {\n max : obj.added_on,\n index: index\n };\n }\n return acc;\n},{index: 0,max: start});\nmsg.start = start;\nvar x = msg.payload.index\nvar name = msg.payload[x].name\nvar hash = msg.payload[x].hash\nvar timeadded = msg.payload.max\nvar sensor = Number(timeadded) * 1000;\t // to milliseconds\nvar dif = Date.now() - sensor;\t // Date.now() returns the number of ms, not a date object\nvar z = {};\nif (dif <= 5 * 60 * 1000) { // if less than 5min\n //var addtwo = new Date(sensor + 2 * 60 * 60 * 1000); // sensor time +2h like in the previous example\n var time1 = (new Date(sensor)).toLocaleString(\"IST\", {\n weekday: 'short',\n month: 'short',\n day: 'numeric',\n hour: '2-digit',\n hourCycle: 'h12',\n minute: '2-digit',\n timeZone: \"Asia/Kolkata\"\n });\n var time2 = time1.replace(/,/g, '');\n z = time2 // to string, assuming you're in india or similar\n\n} else {\n z = \"false\";\n}\nmsg.start = start;\nmsg.max = msg.payload.max;\nmsg.z = z;\nmsg.name = name;\nmsg.hash = hash;\nmsg.timeadded = timeadded;\n//msg.array = array;\nreturn msg;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":3245.60009765625,"y":2558.800048828125,"wires":[["755d46562a25e0a1"]]},{"id":"755d46562a25e0a1","type":"debug","z":"3d8a22efe6ba1aba","name":"debug 90","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":3485.60009765625,"y":2538.800048828125,"wires":[]}]
what i want the result to be:
max:
name:
hash:
index:
use case is to get the name
, hash
and max
from the index we found and you that to find the values inside of that object