I'm in the midst of learning how to use the lodash library, but I've bumped into a problem that I don' think I know how to solve. I want to sort a nested array that looks like this with lodash:
"results": [
{
"id": "12345",
"name": "toy123",
"date_created": "2017-08-29T16:10:37Z",
"date_last_modified": "2019-01-29T17:19:36Z",
"prices": [
{
"currency": "USD",
"amount": "100.00"
},
{
"currency": "EUR",
"amount": "88.23"
},
]
},
{
"id": "54321",
"name": "toy321",
"date_created": "2017-08-29T16:10:37Z",
"date_last_modified": "2019-01-29T17:19:36Z",
"prices": [
{
"currency": "USD",
"amount": "80.00"
},
{
"currency": "EUR",
"amount": "70.58"
},
]
},
]
I want to sort the array based on the prices array that is nested in the given array. The sorting will take consideration of the prices.currency and prices.amount and produce the output as below where the given array is sorted ascendingly based on USD and amount. And another problem I have is that the prices.amount is a string, not a number.
[
{
"id": "54321",
"name": "toy321",
"date_created": "2017-08-29T16:10:37Z",
"date_last_modified": "2019-01-29T17:19:36Z",
"prices": [
{
"currency": "USD",
"amount": "80.00"
},
{
"currency": "EUR",
"amount": "70.58"
},
]
},
{
"id": "12345",
"name": "toy123",
"date_created": "2017-08-29T16:10:37Z",
"date_last_modified": "2019-01-29T17:19:36Z",
"prices": [
{
"currency": "USD",
"amount": "100.00"
},
{
"currency": "EUR",
"amount": "88.23"
},
]
},
]
Many thanks in advance for your kindness and of course your time.