Filter array of objects by comparing nested object properties
We want to return every object in this array unless we have already returned an object with the same articleId.


I would use a Set object to keep track of which articleId values we've already used and then use .filter() to return only the items that pass the test.  Here's a runnable implementation:



let articles = [
  {dateAdded: "31-5-1989", readId: 123, article: { id: 1}}, 
  {dateAdded: "31-5-1989", readId: 124, article: { id: 2}}, 
  {dateAdded: "31-5-1989", readId: 125, article: { id: 1}}
];

function getUniqueArticles(array) {
    let ids = new Set();
    return array.filter(function(item) {
        if (!ids.has(item.article.id)) {
            ids.add(item.article.id);
            return true;
        }
        return false;
    });
}

console.log(getUniqueArticles(articles));






Note: Your articles array does not look valid as there seems to be a missing comma here in each array element and you probably mean to have quotes around the date to make it into a string:

{dateAdded: "31-5-1989", readId: 123, article: { id: 1}}
           ^^^       ^^^           ^^^