Get the sum of all specified elements in an array of objects

后端 未结 5 1892
一个人的身影
一个人的身影 2021-01-28 12:17

I have an array of objects as folllows

[
    {\"width\":128.90663423245883,\"height\":160,\"X\":0,\"Y\":140},
    {\"width\":277.0938568683375,\"height\":263,\"X         


        
5条回答
  •  不要未来只要你来
    2021-01-28 13:07

    function count(stack) {
        var totWidth = 0;
        stack.forEach(function(element) {
          totWidth = totWidth+element.width;
        });
      return totWidth;
    }
    

    working example

提交回复
热议问题