0

I have a fairly simple function that takes in array and loops through it. The length of this array could any length. Within the collection (item) is an entry called date1.

Tried applying this method, but got invalid date message: Return the latest date from array of dates

    function transform(context, input) {
       if (!input){ return ""; }
       for (i=0; i < input.length; i++) {
           var item = artifacts.Artifact(input[i]);
       }
       return returnValue;
    }

What I would like to achieve is to identify the element in the array which has the latest date (including the time) and return fields from that element.

John
  • 1
  • 5
    Welcome to StackOverflow! We would need to see your array to be able to help you. – obscure Apr 11 '19 at 11:18
  • please add your input array – jenil christo Apr 11 '19 at 11:20
  • https://stackoverflow.com/questions/4020796/finding-the-max-value-of-an-attribute-in-an-array-of-objects – Salman A Apr 11 '19 at 11:22
  • I'm not sure how to extract the contents of input array, its generated automatically be another system. This code is run inside another application, kind of like an extension. For simplicity lets say the array just has 2 values - id & date – John Apr 11 '19 at 12:43
  • You have to have access to the data to be able to work on it, you could just console.log it and paste what you find here. – amazonic Apr 11 '19 at 12:55
  • I'm trying this approach, which produces an object but I can't seem to get the values out of it? latest = input.reduce(function (r, a) { return r.date1 > a.date1 ? r : a; }); return JSON.stringify(latest, 0, 8); – John Apr 11 '19 at 13:25

0 Answers0