English 中文(简体)
如何用链条方法从封套阵列中排出物体?
原标题:How to chain Underscore methods to populate an object from nested array?

我有一系列物体,如国家武装部队工作队。 每个目标(小组)都有财产——一组团队行为者。

var nflTeams = [
      { name:  Kansas City Chiefs , playersFirstNames: [ Shane ,  Chad ,  Michael ,  Ronald ,  Blake ,  Noah ], champions: true },
      { name:  Philadelphia Eagles , playersFirstNames: [ Jalen ,  Kenneth ,  Boston ,  Trey ,  Jack ,  Andre ,  Jack ,  Lane ,  Jason ,  Nakobe ], champions: false },
      { name:  Cincinnati Bengals , playersFirstNames: [ Brandon ,  Joe ,  Chris ,  Joe ,  Tyler ,  Trenton ,  Trent ,  Mitchell ,  Alex ,  Trey ,  Ted ], champions: false },
      { name:  San Francisco 49ers , playersFirstNames: [ Jimmy ,  Josh ,  Kyle ,  Jordan ,  Brandon ,  Danny ,  George ,  Tyler ,  Charlie ,  Jake ,  Nick ,  Nick ,  Kevin ], champions: false },
    ];

预期结果——一个名字出现物体:{Joe : 1,my : 2, Jalen : 1 .}

我的目标是通过使用“......”(......)地图(......),_flatten(......),__.reduce()等全线使用_.chain(......)来实现。

我目前的尝试在(......)阶段错失:

ar firstNameOccurence = {  {players firstName} : 0 };
    firstNameOccurence = _.chain (nflTeams)
      .map(function(team) {return team.playersFirstNames})
      .flatten()
      .reduce(function(newObject, firstName){
          console.log ( we have a first name of a player , firstName);
            return newObject[firstName] = 1 ? !newObject[firstName] :  newObject[firstName] += 1;
          
      }, {})
      .value();

现在,这只给我一种真实的美术价值。 我的理想是尝试使用永恒的表达方式,因为它看着更多的代表。 我尝试使用官方文件以及一些实例,例如:ts,,this

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签