Create a Flat version of a nested Object | Breadcrumbs Computation | JavaScript Interview Question
@Yomesh Gupta

JavaScriptIntermediate
694
Do you see value in our efforts?

Devtools Tech is a free platform for Frontend Engineers. It takes a lot of time, effort, and finanical resources to keep the platform running. If you see any value in our work and would like to support us then you can do using the following options.

InternationalDomestic

In many websites like E-commerce, Dashboards, etc there are breadcrumbs that users use to navigate between pages. This question is around that only. Suppose, you are given a nested object from the backend and you need to create a flat version of the object that can be used for breadcrumbs.

const data = {
  name: 'Devtools Tech',
  channel: {
    youtube: {
      link: 'bit.ly/devtools-yt',
      name: 'Devtools Tech',
      subscribe: "true"
    },
    platform: {
      link: 'devtools.tech',
      resources: {
        pages: ['/questions', '/resources']
      },
    }
  }
}

const output = transform(data, 'data');
console.print(output);

/**
  {
    data_name: 'Devtools Tech',
    data_channel_youtube_link: 'bit.ly/devtools-yt',
    data_channel_youtube_name: 'Devtools Tech',
    data_channel_youtube_subscribe: 'true',
    data_channel_platform_link: 'devtools.tech',
    data_channel_platform_resources_pages: [ '/questions', '/resources' ]
  }
**/

Loading IDE...