title: getting student marks with types by combining three arrays but returned a function is a string
body: <p>I have three arrays: students, type, and marks. I want to combine these into one array called student_marks to get each student's marks with mark types. But the object mark function is returned as a string and is not executed in javascript as shown in the picture <a href="https://i.stack.imgur.com/Za1OY.png" rel="nofollow noreferrer">code result</a>.</p>
  <p>I want to get this result:</p>
  <pre><code> {student: '2'; totalmarks: '0'; mark: {'typeid'=&quot;marks&quot; ,'typeid'=&quot;marks&quot; , 'typeid'=&quot;marks&quot; }}
  </code></pre>
  <p>So as a whole the result array which is student_marks  will look like:</p>
  <pre><code> {student: '2'; totalmarks: '0'; mark: {'1'=&quot;1&quot; ,'2'=&quot;2&quot; , '3'=&quot;3&quot; }}
   {student: '3'; totalmarks: '0'; mark: {'1'=&quot;5&quot; ,'2'=&quot;4&quot; , '3'=&quot;7&quot; }}
   {student: '4'; totalmarks: '0'; mark: {'1'=&quot;8&quot; ,'2'=&quot;7&quot; , '3'=&quot;9&quot; }}
  </code></pre>
  <p>Here is my code sample is written in js:</p>
  <pre><code>   let std = [
    1, 2, 3, 4
  ];
  
  let marks = [{
      type: '2',
      marks: '2'
    }, {
      type: '1',
      marks: '1'
    },
    {
      type: '3',
      marks: '3'
    }, {
      type: '2',
      marks: '2'
    },
    {
      type: '1',
      marks: '1'
    }, {
      type: '3',
      marks: '3'
    },
    {
      type: '2',
      marks: '2'
    }, {
      type: '1',
      marks: '1'
    },
    {
      type: '3',
      marks: '3'
    }, {
      type: '2',
      marks: '2'
    },
    {
      type: '1',
      marks: '1'
    }, {
      type: '3',
      marks: '3'
    }
  ];
  
  let type = [2, 1, 3];
  let ri = 0;
  let student_marks = [];
  let registrationIds = [];
  let total_marks = [];
  std.forEach(item =&gt; {
  
    registrationIds[ri] = item;
  
  
    // type[ri]=marks[ri];
  
    // marks:marks[ri];
    student_marks.push({
      student: item,
  
      mark: () =&gt; {
  
        for (let i = 0; i &lt; marks_type.length; i++) {
          // m[marks_type[i]]=marks[i][ri];
          m = [{
            type: marks_type[i],
            marks: marks[i]['marks'],
  
          }];
          // m:{
          //     marks_type[i]=marks[i][ri];
          // };
        }
        console.log(m);
        return m;
      },
  
  
      //  totalmarks: total_marks[ri].value,
    });
  
  
    //  totalmark[ri]=total_marks[ri].value;
  
  
  
  
    ri++;
  });
  
  console.log(student_marks);
  </code></pre>