将两个JSON对象与underline.js合并

将两个JSON对象与underline.js合并,json,node.js,underscore.js,Json,Node.js,Underscore.js,我正在尝试合并以下2个JSON对象,这是Youtube API响应。我试过了 _.values(_.extend(_.indexBy(array1, 'kind'), _.indexBy(array2, 'kind'))) 但它不能正确地合并。我尝试过u0.flant、0.union、0.defaults,但都不适合我 一, 二, 关于如何实现这一点,我没有研究下划线,但您可以尝试使用普通javascriptObject.assign({},object1,object2)。重复的密钥将被覆盖

我正在尝试合并以下2个JSON对象,这是Youtube API响应。我试过了

_.values(_.extend(_.indexBy(array1, 'kind'), _.indexBy(array2, 'kind')))
但它不能正确地合并。我尝试过u0.flant、0.union、0.defaults,但都不适合我

一,

二,


关于如何实现这一点,我没有研究下划线,但您可以尝试使用普通javascript
Object.assign({},object1,object2)
。重复的密钥将被覆盖。希望这有帮助。你期望的输出是什么?所以我将有多组这些,我希望它们像a{[1][2]},b{[1][2]},c{[1][2]}一样合并。。。希望没有使用merge的重复数据。{[1][2]}这在JS中不是有效的Obj定义。没有obj中的键,我们不能使用任何数组。这是正确的吗?{1:{..},2:{…}@risyasin请忽略我给出的语法。这可能更接近。a:{1:{..},2:{..},b:{1:{..},2:{..}。c:{1:{..},2:{..}}。。。
{ kind: 'youtube#playlistItem',
       etag: '"kuL0kDMAqRo3pU7O0pwlO-Lfzp4/tGxY5umSWnuSkk1adS4H8nsd7nI"',
       id: 'PLhAf_GEuRunTjOdIMNbFsPSMLcbkw3RoTqruH97SaMEs',
       snippet: 
        { publishedAt: '2015-12-13T12:16:47.000Z',
          channelId: 'UCwy6X3JB24VTsDFqMwdO5Jg',
          title: 'John Hockenberry: We are all designers',
          description: 'http://www.ted.com Journalist John Hockenberry tells a personal story inspired by a pair of flashy wheels in a wheelchair-parts catalogue -- and how they showed him the value of designing a life of intent. (From The Design Studio session at TED2012, guest-curated by Chee Pearlman and David Rockwell.)\n\nTEDTalks is a daily video podcast of the best talks and performances from the TED Conference, where the world\'s leading thinkers and doers give the talk of their lives in 18 minutes. Featured speakers have included Al Gore on climate change, Philippe Starck on design, Jill Bolte Taylor on observing her own stroke, Nicholas Negroponte on One Laptop per Child, Jane Goodall on chimpanzees, Bill Gates on malaria and mosquitoes, Pattie Maes on the "Sixth Sense" wearable tech, and "Lost" producer JJ Abrams on the allure of mystery. TED stands for Technology, Entertainment, Design, and TEDTalks cover these topics as well as science, business, development and the arts. Closed captions and translated subtitles in a variety of languages are now available on TED.com, at http://www.ted.com/translate\n\nIf you have questions or comments about this or other TED videos, please go to http://support.ted.com',
          thumbnails: 
           { default: 
              { url: 'https://i.ytimg.com/vi/ti_i-M3pk5M/default.jpg',
                width: 120,
                height: 90 },
             medium: 
              { url: 'https://i.ytimg.com/vi/ti_i-M3pk5M/mqdefault.jpg',
                width: 320,
                height: 180 },
             high: 
              { url: 'https://i.ytimg.com/vi/ti_i-M3pk5M/hqdefault.jpg',
                width: 480,
                height: 360 },
             standard: 
              { url: 'https://i.ytimg.com/vi/ti_i-M3pk5M/sddefault.jpg',
                width: 640,
                height: 480 },
             maxres: 
              { url: 'https://i.ytimg.com/vi/ti_i-M3pk5M/maxresdefault.jpg',
                width: 1280,
                height: 720 } },
          channelTitle: 'Seong Lee',
          playlistId: 'PLy7hFLa6kbitaVkEcgPEt6GlfVjuyO91K',
          position: 30,
          resourceId: { kind: 'youtube#video', videoId: 'ti_i-M3pk5M' } },
       contentDetails: { videoId: 'ti_i-M3pk5M' } },
}
{ kind: 'youtube#videoListResponse',
    etag: '"kuL0kDMAqRo3pU7O0pwlO-Lfzp4/BQsUkCeR_vYw5Am_P0zDQ65R2RI"',
    pageInfo: { totalResults: 1, resultsPerPage: 1 },
    items: 
     [ { kind: 'youtube#video',
         etag: '"kuL0kDMAqRo3pU7O0pwlO-Lfzp4/63882pNOoZMxxAveXDjjDGxrL6g"',
         id: 'ti_i-M3pk5M',
         contentDetails: 
          { duration: 'PT19M44S',
            dimension: '2d',
            definition: 'hd',
            caption: 'true',
            licensedContent: true } },
       [length]: 1 ] }