0

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

1 Answer 1

1

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)
}
Sign up to request clarification or add additional context in comments.

4 Comments

yes,this did the work. the elements return as an array, but I also need this to pass into my studentId.
const elements = this.classlists.map(e => (this.form.studentId = e.id)); i tried this but what i get is only the last value
just add a line at the bottom this.form.studentId = elements inside insertScore
oh i alerady get the studentId const elements = this.classlists.map(e => e.id); this.form.studentId = elements;. Thank you for your help

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.