I have such json structure: {    maxPageIndex:1,    totalItems:1,    currentPageIndex:1,    currentPage:[        {id:1,name:Hummer,compareItems:            [{companyId:1,companyName:Makoto,compareItemId:10,compareItemName:MyHummer},            {companyId:3,companyName:Boshst,compareItemId:11,compareItemName:Hummer tools}]        },        {id:2,name:Refrigerator,compareItems:            [{companyId:1,companyName:LeGe,compareItemId:12,compareItemName:iRefrigerator},             {companyId:2,companyName:Condi,compareItemId:13,compareItemName:Refrigerator P48},             {companyId:3,companyName:Boshst,compareItemId:14,compareItemName:Refrigerator N1},             {companyId:4,companyName:Atlanta,compareItemId:15,compareItemName:_Refrigerator},             {companyId:5,companyName:ChinWeui,compareItemId:16,compareItemName:Refrigerator super}]        },        {id:3,name:eBook,compareItems:            [{companyId:2,companyName:Condi,compareItemId:17,compareItemName:iBook}]        }  ]}And main trouble that i should display in table same structure...I mean for every item in currentPage i'm displaying in table compareItems. BUT! there are not the same length, and my table is like stairs, and i need to make it the same size, i mean that for example max length is in Refrigerator object (5), and Hummer&eBook compareItems should be 5 length too (just emty object with company data with sorting via Id).As result i need such table:{    maxPageIndex:1,    totalItems:1,    currentPageIndex:1,    currentPage:[        {id:1,name:Hummer,compareItems:            [{companyId:1,companyName:LeGe,compareItemId:10,compareItemName:MyHummer},            {companyId:2,companyName:Condi},            {companyId:3,companyName:Boshst,compareItemId:11,compareItemName:Hummer tools},            {companyId:4,companyName:Atlanta},            {companyId:5,companyName:ChinWeui}]        },        {id:2,name:Refrigerator,compareItems:            [{companyId:1,companyName:LeGe,compareItemId:12,compareItemName:iRefrigerator},             {companyId:2,companyName:Condi,compareItemId:13,compareItemName:Refrigerator P48},             {companyId:3,companyName:Boshst,compareItemId:14,compareItemName:Refrigerator N1},             {companyId:4,companyName:Atlanta,compareItemId:15,compareItemName:_Refrigerator},             {companyId:5,companyName:ChinWeui,compareItemId:16,compareItemName:Refrigerator super}]        },        {id:3,name:eBook,compareItems:            [{companyId:1,companyName:LeGe},            {companyId:2,companyName:Condi,compareItemId:17,compareItemName:iBook},            {companyId:3,companyName:Boshst,compareItemId:11,compareItemName:Hummer tools},            {companyId:4,companyName:Atlanta},            {companyId:5,companyName:ChinWeui}]        }  ]}Is it a little bit clear?)And main goal: i'm a beginner in js, and i wrote such function to do this (i'm using lodash lib):ctrl.companys = [];  ctrl.products = /*data from question*/  _.each(ctrl.products.currentPage, function (rootEl) {    _.each(rootEl.compareItems, function (compareItemsElement) {      if (!_.some(ctrl.companys, {Id: compareItemsElement.companyId}) && !_.isUndefined(compareItemsElement.companyId)){        ctrl.companys.push({Id: compareItemsElement.companyId, Name: compareItemsElement.companyName});      }    });  });  ctrl.companys = _.sortBy(ctrl.companys, 'Id');  _.each(ctrl.products.currentPage, function (rootEl, rootElIndex) {    _.each(rootEl.compareItems, function (compareItemsElement, compareItemsElementIndex) {      _.each(ctrl.companys, function (company, companyIndex) {        if (!_.some(rootEl.compareItems, {companyId: company.Id})){          ctrl.products.currentPage[rootElIndex].compareItems.push({companyId: company.Id, compareItemName: '-'});          ctrl.products.currentPage[rootElIndex].compareItems = _.sortBy(ctrl.products.currentPage[rootElIndex].compareItems, 'companyId');        }      });    });  });and it works... but! i think that this code is to ugly... Maybe there is a better way of doing that?
How to make object childs the same length as maximal child
javascript;angular.js;lodash.js