As @Barmar said it would probably be best to store that data in an object, not an array. However, if you get the data in such structure from an API you can go about it in a few ways.
Parse the data:
array = JSON.parse(`[
{
"name": "First object",
"info": [
{"amount": "2 people"},
{"description": "this is a description"}
]
},
{
"name": "Second object",
"info": [
{"description": "this is a description"},
{"amount": "1 furniture"}
]
},
{
"name": "Third object",
"info": [
{"amount": "3 animals"},
{"description": "this is a description"}
]
}
]`)
You're probably gonna use it later so might as well map it to flat objects:
flat_array = array.map(x => Object.assign({ name: x.name }, ...x.info)
Then you can sort it by simply doing:
flat_array.sort((a, b) => a.amount.localeCompare(b.amount))
Otherwise, if you just want to sort the data, without modifying it, you can do:
array.sort((a, b) => Object.assign({}, ...a.info).amount.localeCompare(Object.assign({}, ...b.info).amount))
following the Object.assign
example. Or as other people suggested in the comments:
array.sort((a, b) => a.info.find(x => "amount" in x).amount.localeCompare(b.info.find(x => "amount" in x).amount))