I
I
Ivan Ivanov2019-07-02 14:37:42
JavaScript
Ivan Ivanov, 2019-07-02 14:37:42

How to populate an array using a for loop?

Good afternoon, I'm trying to output an array of consecutive numbers, which should fill with a loop for. I know that it can be made easier with the help v-for, but I need it exactly as I described earlier. I tried to do so, but it did not give any results.
My app.vue:

<template>
  <div id="app">
    <p>{{ mounthDays }}</p>
  </div>
</template>

<script>
export default {
  name: 'app',
  data () {
    return {
     mounthDays: []
    }
  },
  mounted() {
      for (var i = 1; i <= 31; i++) {
        return this.mounthDays.push(i)
      }
    }
  }
</script>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
McBernar, 2019-07-02
@McBernar

Return in a for loop? Something new.
My advice to you is to at least read learn.javascript.ru. Don't try to work with frameworks without understanding js.

M
myaca, 2019-07-02
@myaca

Play with it :)

const amount = 31;

const arr = Array.from(new Array(amount), (item, index) => index);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question