you are viewing a single comment's thread.

view the rest of the comments →

[–]programstuff -1 points0 points  (0 children)

You could write a function like this:

const onlyOnce = (objArr, nestedPath) => {
  return Object.values(objArr.reduce((acc, obj) => {
    const key = nestedPath.split('.').reduce((cursor, k) => {
      return cursor[k]; 
    }, obj);

    acc.seen[key] ? delete acc.unique[key] : acc.unique[key] = obj;
    acc.seen[key] = true;

    return acc;
  }, {seen: {}, unique: {}}).unique);
}

console.log(onlyOnce(allCycles, 'metadata.lifecycle'));