javascript - Filtering out duplicate objects before pushing to an array? -


i attempting filter out duplicate objects before pushing each object array.

function collaborators() {   var api = '/docs/' + doc_id + '/json';   $.getjson(api, {format: "json"} ).done(function(data) {     var collaborators = [];     (var = 0; < data.notes.length; i++) {       if ( data.notes[i].author === data.notes[i+1].author) {         console.log('dup found')         console.log(data.notes[i].author)       } else {         collaborators.push(data.notes[i].author);       }     }   }); } 

the console showing "uncaught typeerror: cannot read property 'author' of undefined". seeing duplicate entry in console.log(data.notes[i].author), array empty. needs corrected?

in last iteration of loop, there no i+1:

data.notes[i+1] 

since undefined, calling .author on blow up. error indicates, data.notes[i+1] undefined, therefore there no property author of undefined.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -