[Vuejs]-How to place these 2 arrays inside separate objects and push to the main array in JS?

0👍

A good straight-forward answer can be given if you say the intention behind that structuring otherwise you could just use a method to accomplish that.

{
  data() {
    return {
      productsByCategory: [],
      productsByTag: [],
      filteredProducts: []
    };
  },
  methods: {
    groupProducts() {
      this.filteredProducts.push({
        type: "Category",
        products: this.productsByCategory
      });
      this.filteredProducts.push({
        type: "Tag",
        products: this.productsByTag
      });
    }
  }
}

Leave a comment