Answer the question
In order to leave comments, you need to log in
How to get a property in an array to sort?
{
"ammo": [{
"caliber": "11,43x23",
"items": [{
"name": ".45 FMJ",
"caliber": "11,43x23",
"damage": "72",
"arm_pentra": "19",
"arm_damage": "36%",
"bullet_frag": "1%",
"speed": "285",
"ricochet": "7%",
"without_armor": [{
"min": "2",
"avg": "2",
"max": "2"
}],
"gen4": [{
"min": "22",
"avg": "22",
"max": "22"
}],
"zhuk6": [{
"min": "21",
"avg": "21",
"max": "21"
}]
},
{
"name": ".45 RIP",
"caliber": "11,43x23",
"damage": "72",
"arm_pentra": "19",
"arm_damage": "36%",
"bullet_frag": "1%",
"speed": "285",
"ricochet": "7%",
"without_armor": [{
"min": "1",
"avg": "1",
"max": "1"
}],
"gen4": [{
"min": "15",
"avg": "15",
"max": "15"
}],
"zhuk6": [{
"min": "15",
"avg": "15",
"max": "15"
}]
}
]
},
{
"caliber": "12,7x108",
"items": [{
"name": "12.7Б3T",
"caliber": "12,7x108",
"damage": "199",
"arm_pentra": "80",
"arm_damage": "95%",
"bullet_frag": "17%",
"speed": "818",
"ricochet": "38%",
"without_armor": [{
"min": "1",
"avg": "1",
"max": "1"
}],
"gen4": [{
"min": "1",
"avg": "1",
"max": "2"
}],
"zhuk6": [{
"min": "1",
"avg": "1",
"max": "2"
}]
},
{
"name": "Б-32",
"caliber": "12,7x108",
"damage": "182",
"arm_pentra": "88",
"arm_damage": "88%",
"bullet_frag": "17%",
"speed": "818",
"ricochet": "38%",
"without_armor": [{
"min": "1",
"avg": "1",
"max": "1"
}],
"gen4": [{
"min": "1",
"avg": "1",
"max": "2"
}],
"zhuk6": [{
"min": "1",
"avg": "1",
"max": "2"
}]
}
]
},
sortByCaliber() {
this.ammo_data.sort((a, b) => {
a.caliber.localCompare(b.name)
});
},
sortByDamage() {
this.ammo_data.sort((a, b) => {
return a.items.damage - b.items.damage;
});
},
Answer the question
In order to leave comments, you need to log in
Convert the ammo array to a flat items array, something like:
let items = ammo.reduce((accum, el) => accum.concat(el.items), []);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question