1

I want to display the values in the day object such as: Sunday, Monday, etc.

enter image description here

For now, here my code:

<div class="col-md-3 col-sm-6" v-for="item in result" v-bind:key="item.schedule_id"> {{ item.day }} </div> 

My result:

[ "Monday", "Wednesday" ] 

3 Answers 3

2

You can do another loop as

 <div class="col-md-3 col-sm-6" v-for="item in result" v-bind:key="item.schedule_id"> <div v-for="(day , index) in item.day" :key="index"> {{day}} </div> </div> 
Sign up to request clarification or add additional context in comments.

3 Comments

But, for the result, how to retain the comma?
you can add comma after {{day}} like {{day}} ,
I actually want the commas to be between the arrays, but even this is fine, thanks
2

If you want just return the days use the flatMap function :

<div class="col-md-3 col-sm-6" v-for="day in result.flatMap(item=>item.day)" v-bind:key="day"> {{ day }} </div> 

if you want to separate them by comma use this :

<div class="col-md-3 col-sm-6" > {{ result.flatMap(item=>item.day).join(',') }} </div> 

or between arrays:

<div class="col-md-3 col-sm-6" > {{ result.map(item=>item.day).join(',') }} </div> 

Comments

2

I think it's a better and easy solution

<div class="col-md-3 col-sm-6" v-for="item in result" :key="item.schedule_id"> {{ item.day.join(',') }} </div> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.