gpt4 book ai didi

Lodash - 如何对数组的数组长度求和

转载 作者:行者123 更新时间:2023-12-01 09:47:22 25 4
gpt4 key购买 nike

我有一个数组数组

const myArrays = [
[ 1, 2, 3, 4], // length = 4
[ 1, 2], // length = 2
[ 1, 2, 3], // length = 3
];

如何获取所有子数组的总长度?

const length = 4 + 2 + 3

最佳答案

你可以使用_.sumBy

const myArrays = [
[ 1, 2, 3, 4], // length = 4
[ 1, 2], // length = 2
[ 1, 2, 3], // length = 3
];

var length = _.sumBy(myArrays, 'length');
console.log("length =", length);
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js'><</script>

关于Lodash - 如何对数组的数组长度求和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45852931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com