I have this array :
data = {
"lists": {
"list-1": {
"id": "list-1",
"title": "list1",
"cards": [
{
"id": "20",
"title": "title"
},
{
"id": "2",
"title": "title"
}
]
},
"list-2": {
"id": "list-2",
"title": "list2",
"cards": [
{
"id": "4",
"title": "title"
},
{
"id": "3",
"title": "title"
}
]
}
}
}
I want to find the highest item with "id" as key. So here it would be "20"
I know how to do within an array but not from a multi dimensional array like here
const list = data.lists[listId]
3
Answers
Reduce the lists to a min value of card ids:
If you want the maximum speed, just loop:
You can find the highest item with the "id" key from the given multidimensional array by iterating through the nested structures and keeping track of the highest value found. Here’s a JavaScript function that accomplishes this:
Most Efficient method: 120OP/s
Another way to write it: 86K OP/s
One last attempt… this can be done many ways: 86K OP/s