Reputation: 25
I'm trying to figure out how to convert info
into an array to compare it with another array.
This is my code
<input type="checkbox" v-model="info.q1">
<input type="checkbox" v-model="info.q2">
<input type="checkbox" v-model="info.q3">
Answers[],
info : {
q1: '4',
q2: '4',
q3: '4'
}
I'm trying to get something like the below:
var answers = [{q1: 4},{q2: 4}]
Upvotes: 0
Views: 1639
Reputation: 20745
Make a computed property that calculates answers
based on info
.
computed: {
answers () {
return Object.entries(this.info).map(
([key, value]) => { [key]: value }
)
}
}
Upvotes: 1
Reputation: 816
You can make a Computed Property
with the name answers
like:
answers () {
return Object.entries(this.info).map( ([key, value]) => ({ [key]: value }) )
}
After creating computed property
you can call it like this.answers
.
or
You can make make in method like:
methodName(){
const answers = Object.entries(this.info).map( ([key, value]) => ({ [key]: value }) )
}
Upvotes: 2