Answer the question
In order to leave comments, you need to log in
How to find an object in an array with arrays whose value is greater than other objects?
const arr = [
[
{name: 'Name1', age: 3},
{name: 'Name1', age: 5}
],
[
{name: 'Name1', age: 1},
{name: 'Name1', age: 7}
]
[
{name: 'Name1', age: 2},
{name: 'Name1', age: 10}
]
]
Answer the question
In order to leave comments, you need to log in
In the title of the question:
find object
find the largest value
arr.flat().reduce((max, n) => max?.age > n.age ? max : n, null)
Math.max(...arr.flat().map(n => n.age))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question