0

Following is the VueJs data object.

menu: {
    title_en: '',
    title_ar: '',
    price: '',
    preferences: 
    [
        {
            title_en: '',
            title_ar: '',
            items: [
                {
                    title_en: '',
                    title_ar: '',
                    price: '',
                }
            ] 
        }
    ]
}

I can easily add data at the first level, as below.

this.menu.preferences.push({
    title_en: '',
    title_ar: '',
    items: [
        {
            title_en: '',
            title_ar: '',
            price: '',
        }
    ] 
});

But this time, how can we add/push data to second or third level, when needed. Tried below but failed.

this.menu.preferences.items.push({
    title_en: '',
    title_ar: '',
    price: '',
});
zarpio
  • 10,380
  • 8
  • 58
  • 71
  • 1
    `this.menu.preferences[0].items.push(/*...*/)` – str Jul 15 '20 at 13:12
  • this.menu.preferences is an array and not an object we need to access the items key in the object at index 0 so we'll access it this was `this.menu.preferences[0]` to access the key `items` `this.menu.preferences[0].items` which is an array, so now we need to push to it `this.menu.preferences[0].items.push(enter your object here)` – M.Ghali Jul 15 '20 at 13:23

0 Answers0