Sum of same object name in javascript

前端 未结 4 1511
[愿得一人]
[愿得一人] 2021-01-16 04:33

Hi friends I\'m beginner for javascript how i sum same n no\'s of object name corresponding value and push the result to new array.see this is sample object

va

4条回答
  •  醉话见心
    2021-01-16 05:31

    const newArray = initialArray.map(({team_name, ...restProps}) => {
      return {
        [team_name]: {...restProps}
      };
    });
    

    See:

    • Arrow functions
    • Spread operator
    • Array.prototype.map
    • Computed property names

提交回复
热议问题