Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Push objects from array into specific fields of another array

I’ve a method to get the data (days, month) from the current week.
I want to push this data to an array in the specific object field and later loop through this array to display it.

I really have no idea how to do this.

<div v-for="day in days" :key="day.index">
  <p>{{ day.month }}</p>
  <p>{{ day.numberDay }}</p>
  <p>{{ day.textDay }}</p>
</div>
  data() {
    return {
      // days: [{ textDay: "", numberDay: "", month: "" }]
      days: []
      
    }
  },

  methods: {
    getCurrentWeek() {
      const currentDate = moment();

      const weekStart = currentDate.clone().startOf('isoWeek');

      const days = [];

      for (let i = 0; i <= 6; i++) {
        days.push({ textDay: moment(weekStart).add(i, 'days').format("dddd") });
        days.push({ numberDay: moment(weekStart).add(i, 'days').format("Do") });
        days.push({ month: moment(weekStart).add(i, 'days').format("MMMM") });
      }

    this.days = days
    }
  }

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should be pushing values in days array like this.
Please revert, if this solves your problem.

    for (let i = 0; i <= 6; i++) {
days.push({textDay: moment(weekStart).add(i, 'days').format("dddd"), numberDay: moment(weekStart).add(i, 'days').format("Do"), month: moment(weekStart).add(i, 'days').format("MMMM")});
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading