Crumb Builder

by Sam Fereday

HTML

<div id="path">
...
</div>

JavaScript 1.7

const items = [{
    id: '1',
    parentId: null,
    name: 'One',
    path: '/1/'
  },
  {
    id: '2',
    parentId: '1',
    name: 'Two',
    path: '/1/2/'
  },
  {
    id: '3',
    parentId: '2',
    name: 'Three',
    path: '/1/2/3'
  },
  {
    id: '4',
    parentId: '1',
    name: 'Four',
    path: '/1/4/'
  }
];

const currentItemId = '3';

const splitPath = items.find(x => x.id === currentItemId)
  .path.split('/').filter(n => n);

const breadPath = splitPath.map(id => ({ ...items.find(item => item.id === id) }));

console.log(breadPath);