JSFiddle - React, Tailwind, and code Playground

by Eugen Sunic

JavaScript

settings = [

  {
    path: '/templates/pictures.php',
    url: '/pictures',
    label: 'Pictures',
    component: 'tab',
    template: 'default'
  },
  {
    path: '/templates/post-article.php',
    url: '/user/:username',
    component: 'table',
    template: 'default',
    children: [{
      path: '/templates/post-article-highlights.php',
      url: '/user/:username/highlights',
      component: 'table',
      template: 'default',
      children: [{
          path: '/templates/post-article-highlights.php',
          url: '/user/:username/blabasdasabdass',
          component: 'table',
          template: 'default'
        }

      ]
    }]
  }

]

function findArray(array) {
  var new_array = [];

  for (var i = 0; i < array.length; i++) {
    if (array[i].url) {
      let obj = {};
      obj['url'] = array[i].url;
      obj['children'] = array[i].children;
  
      new_array.push(obj);

    }
    if (Array.isArray(array[i].children)) {
      new_array = new_array.concat(findArray(array[i].children));
    }
  }
  return new_array;
}

console.log(findArray(settings));