My data is
[
[{"2018":63},{"2019":28},{"2020":21}],
[{"2018":103},{"2019":200},{"2020":54}],
[{"2017":74},{"2019":76},{"2020":31}]
]
and I want array of sum of the values like
[112, 357, 181]
Thanks
Map the array. Flatten each sub-array to an array of values, and sum them:
const arr = [[{"2018":63},{"2019":28},{"2020":21}],[{"2018":103},{"2019":200},{"2020":54}],[{"2017":74},{"2019":76},{"2020":31}]]
const result = _.map(
arr,
s => _.sum(_.flatMap(s, _.values))
)
console.log(result)
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js" integrity="sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>