I am attempting to filter out duplicate objects before pushing each object to an array.
function collaborators() {
var api = '/docs/' + doc_id + '/json';
$.getJSON(api, {format: "json"} ).done(function(data) {
var collaborators = [];
for (var i = 0; i < 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 is showing "Uncaught TypeError: Cannot read property 'author' of undefined". However I am seeing the duplicate entry in console.log(data.notes[i].author)
, but the array is empty. What needs to be corrected?