Вы можете использовать это утверждение в 1 строку.
let maxLen = Math.max(...Object.keys(obj).map((key) => Math.max(...obj[key].map((o) => o.label.length))));
Пример на узле REPL
> var obj = {
... "array1": [
... {
..... "label": "something1",
..... "ref": "option2a"
..... },
... {
..... "label": "something2",
..... "ref": "option2b"
..... },
... {
..... "label": "something3",
..... "ref": "option2a"
..... },
... {
..... "label": "something4",
..... "ref": "option2a"
..... },
... {
..... "label": "something5",
..... "ref": "option2a"
..... }
... ],
... "array2": [
... {
..... "label": "somethinglongest",
..... "ref": "option3a"
..... },
... {
..... "label": "Other",
..... "ref": "option3b"
..... }
... ]
... }
undefined
>
> Math.max(...Object.keys(obj).map((key) => Math.max(...obj[key].map((o) => o.label.length))))
16
>
Подробный обзор
let keys = Object.keys(obj);
let maxLens = keys.map((key) => {
let arr = obj[key];
return Math.max(...arr.map((o) => o.label.length))
});
let max = Math.max(...maxLens);
console.log(keys); // [ 'array1', 'array2' ]
console.log(maxLens); // [ 10, 16 ]
console.log(max); // 16
А вот пример, чтобы помочь вам.
> Math.max(4, 5, 7)
7
>
> Math.max([4, 5, 7])
NaN
>
> Math.max(...[6, 7])
7
>
> let a = [2, 4, 5]
undefined
>
> a2 = a.map((num) => num ** 2)
[ 4, 16, 25 ]
>
> a3 = a.map((num) => num + 2)
[ 4, 6, 7 ]
>