cupcave
cupcave

Reputation: 55

vuejs: how to pass the value to data as Array?

I'm passing the value of object as props into my "data" studentId inside the form

data() {
    return {
      form: new Form({
        studentId: []
      })
    };
  },

In my method, the classlists has initial value, which are the id of students

insertScore() {
      let students = this.classlists;   //<---this is my props
      let element = [];
      let s = [];
      for (let index = 0; index < students.length; index++) {
        element = students[index].id; 
      }
    }

        //id: 7
        //id:29
        //id:30

What i need is to make my classlists ids to be an array and store it into my studentId like studentId = [7,29,30] , but what i'm getting when i console.log is separate Ids

Props: my props

Upvotes: 0

Views: 1189

Answers (1)

DedaDev
DedaDev

Reputation: 5249

I'm not sure if this is what are you trying to achieve but if you want new array with only specific property from the classlist, this should do work.

insertScore() {
    const elements = this.classlists.map(e=>e.id)
}

Upvotes: 1

Related Questions