0

I'm trying to figure out a way to dedupe JSON arrays based on the _prop.Invoice_Number__c value returned by a Remote Object retrieve. Please see attached screenshot of the JSON as viewed through a JSON editor to see the structure of the array.

I played around with lodash _uniq but with no success. Any pointers would be much appreciated.

enter image description here

  • Where is this JSON array? Apex or JavaScript? – Boris Bachovski Jun 23 '15 at 22:51
  • Unique... how? Those are different line items on the same invoice, it appears. I don't see how that's not unique already. – sfdcfox Jun 23 '15 at 23:14
  • @Bachovski - JavaScript – vshake Jun 24 '15 at 15:38
  • @sfdcfox Correct - I'm trying to build a expandable datatable with the invoice header information for the primary rows that can be expanded to item information. I could normalize the source data and leverage separate objects and build out the table that way but having encountered this situation with the denormalized data I am interested in how one would approach parsing out the JSON data. Thanks. – vshake Jun 24 '15 at 15:53
  • @vshake I see what you're going for... Technically, I don't see anything wrong with var output = {}; input.forEach(function(e,i,a) { output[e._props.Invoice_Number__c] = output[e._props.Invoice_Number__c] || []; output[e._props.Invoice_Number__c].push(e); }); There's a way to use _.uniq in the same way, but I'm not familiar with lodash (although, now that you've mentioned it, I'll probably learn it). – sfdcfox Jun 24 '15 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.