I have a Vue component in which I select a specific value from an array of objects then attempt to copy some fields from that value into Vue data
<div class="container">
<h4>Add Item</h4>
<form @submit.prevent="addItem(item.Code)">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label for="ItemCode">Code</label>
<select
id="ItemCode"
v-model="item.Code"
>
<input
v-model="item.Code"
type="hidden"
>
<option
v-for="part in PartCodes"
:key="part"
>
{{ part }}
</option>
</select>
.
.
.
</form>
</div>
where the data is
data() {
return {
item: {},
parts: [],
};
},
computed: {
PartCodes: function () {
return [...new Set(this.parts.map(p => p.Code))];
},
},
created() {
let uri = '/parts';
if (process.env.NODE_ENV !== 'production') {
uri = 'http://localhost:4000/parts';
}
this.axios.get(uri).then(response => {
this.parts = response.data;
});
},
methods: {
addItem(selectCode) {
let uri = '/items/create';
if (process.env.NODE_ENV !== 'production') {
uri = 'http://localhost:4000/items/create';
}
let selectPart = this.parts.filter( obj => {
return obj.Code === selectCode;
});
this.item.Description = selectPart.Description;
this.item.Cost = selectPart.Cost;
this.item.Price = selectPart.Price);
this.axios.post(uri, this.item)
.then(() => {
this.$router.push({name: 'QuoteIndex'});
});
}
}
};
When I log the object 'selectPart' it has the correct fields but assigning these fields into the object 'items' results in 'undefined' values
I must be doing something wrong with scope but I don't know what is wrong.
Please suggest how I can copy fields with this Component

selectPartis the result ofArray.prototype.filter(), won't it be an array?console.log(selectPart). I say it's an array which is whyselectPart.DescriptionisundefinedCode: "CS-KVM-8P" Cost: 1688.37 Description: "INTEGRATED DIGITAL 8-PORT KVM OVER IP SWITCH" Price: 8410 _id: "5d9eb36a9814894c5cea8f83"looks like an object