E
E
Erl2020-07-25 16:33:31
JavaScript
Erl, 2020-07-25 16:33:31

How can you sort when an array is in an array?

JSON

{
            "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"
                    }]
                }
            ]
        },


Output in a template

<tbody v-for="data in ammo_data" :key="data.caliber" class="tbody">
    <template v-if="caliber === '' || data.caliber == caliber">
        <tr v-for="items in data.items" :key="items.name">


Sort attempt

sortByDamage() {
      let items = this.ammo_data.reduce((accum, el) => accum.concat(el.items), []);
      items.sort((a, b) => 
        a.damage - b.damage);
      this.ammo_data.items = items;
    },


How can this table be sorted?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question