We help IT Professionals succeed at work.

JavaScript Arrays and objects

Howard Bash
Howard Bash asked
on
148 Views
Last Modified: 2017-05-04
I am getting back an object from a rest call which contains results from a SharePoint REST call.  The returned data has dups (which are indeed in the list).

I want to dedup the data and then return it to be used elsewhere.  It looks something like the following:

function DedupeList(flist) {
                var listlength = flist.length;
                var newObject=[];
                var currentID = flist.results[0].FID;
                newObject.push(flist.results[0])
                //
                for (var ptr=1; ptr<listlength; ptr++) {
                                if (flist.results[ptr].FID!=currentID) {
                                                newObject.push(flist.results[ptr]);
                                                currentID = flist.results[ptr].FID;
                                }
                }
                
                return newFilmsObject;                
}

Open in new window


The issue is I want to return an object like the passed in data set from the REST call and am not sure if the array I am using to build the deduped set will work.
Comment
Watch Question

CERTIFIED EXPERT
Distinguished Expert 2017

Commented:
Would you like to give us an object sample to see the structure of the object that you want to dedup?
Commented:
This problem has been solved!
(Unlock this solution with a 7-day Free Trial)
UNLOCK SOLUTION

Commented:
This question has been inactive for 14 days, with no comment from the author. Force Close this question, answer to code that gives a duplicate cleared array.