As a newcomer to Vue.js, I am dealing with data stored in an array object as shown below when using vue-multiselect:
[
{
"id": 1,
"add_on_type": "Xtra",
"name": "test",
"price": 12,
"created_at": "2020-06-25 10:12:43",
"updated_at": "2020-06-25 10:12:43"
},
{
"id": 3,
"add_on_type": "Xtra",
"name": "Some x",
"price": 120,
"created_at": "2020-06-30 05:47:52",
"updated_at": "2020-06-30 05:47:52"
}
]
However, my function requires me to access the data in key:value
format like this:
"xtra": {
// key: value
0: 1
1: 3
}
Unfortunately, instead of getting just the ID
values from the array, I'm receiving all the array objects. Here is a snippet of my code where I'm struggling to extract only the id
s:
this.$axios
.get("items/" + this.item)
.then(res => {
// The line below shows how I currently access the array object, but I need only the ids.
data.xtra = this.extra;
console.log(data);
})
.catch(err => {
throw err;
});
While some may find this task straightforward, I'm having difficulty figuring it out on my own. Any guidance or assistance would be greatly appreciated. Thank you in advance!