JavaScript How to avoid multiple map functionality

I have two objects. First one have entire school full details of students record. Example like

var first = {
 students: 
    [
     { id:'1', name:"suresh", age:"20", degree:"BSc", status:"obsent"},
     { id:'2', name:"ramesh", age:"21", degree:"BCom", status:"present"},
     { id:'3', name:"rajesh", age:"19", degree:"BA", status:"leave"},
     { id:'4', name:"satish", age:"28", degree:"BL", status:"obsent"}
   ]
}

Second one have particular class students information about the status of the student for that day. Example like

var second ={
 students: 
    [
     { id:'1',status:"present"},
     { id:'12',status:"obsent"},
     { id:'3',status:"obsent"},
     { id:'14',status:"leave"}
    ]
}

Now I need to compare the student id and need to display the status based on the result. I have achieved in the following way.

 items = first.students.map(function(item){
      status =item.status;
      second.students.map(function(key){
         if(key.id == item.id) { status = key.status }
      });
      return "<tr><td>"+item.name+"</td><td>"+item.age+"</td><td>"+item.degree+"</td><td>"+status+"</td></tr>";
  });

  $('table#main tbody').html(items);

The above code is working fine. But if you look at my code, I have used the map functionality multiple times. I feel that I have done something wrong in the performance wise. Is that possible to reduce using the map twice or any other better way to achieve the same result. Please suggest me.

Code Snippet

var first = {
  students: 
  [
   { id:'1', name:"suresh", age:"20", degree:"BSc", status:"obsent"},
   { id:'2', name:"ramesh", age:"21", degree:"BCom", status:"present"},
   { id:'3', name:"rajesh", age:"19", degree:"BA", status:"leave"},
   { id:'4', name:"satish", age:"28", degree:"BL", status:"obsent"}
  ]
}
var second ={
  students: 
  [
   { id:'1',status:"present"},
   { id:'12',status:"obsent"},
   { id:'3',status:"obsent"},
   { id:'14',status:"leave"}
  ]
}

items = first.students.map(function(item){
   status =item.status;
   second.students.map(function(key){
      if(key.id == item.id) { status = key.status }
   });
   return "<tr><td>"+item.name+"</td><td>"+item.age+"</td><td>"+item.degree+"</td><td>"+status+"</td></tr>";
});

$('table#main tbody').html(items);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="main" cellspacing="2" border="1">
<thead>
  <tr>
    <th>Name</th>
    <th>Age</th>
    <th>Degree</th>
    <th>Stauts</th>
  </tr>
</thead>
<tbody>
</tbody>
</table>
</tbody>

</table>
Answer:1

The complexity will be better if you build an object which keys are id and values are status from second.students then you update status in first.students based on this object:

var first = {
  students: 
  [
   { id:'1', name:"suresh", age:"20", degree:"BSc", status:"obsent"},
   { id:'2', name:"ramesh", age:"21", degree:"BCom", status:"present"},
   { id:'3', name:"rajesh", age:"19", degree:"BA", status:"leave"},
   { id:'4', name:"satish", age:"28", degree:"BL", status:"obsent"}
  ]
}
var second ={
  students: 
  [
   { id:'1',status:"present"},
   { id:'12',status:"obsent"},
   { id:'3',status:"obsent"},
   { id:'14',status:"leave"}
  ]
}

var statusById= second.students.reduce(function(m, e) {
    m[e.id] = e.status; 
    return m;
}, {});    

items = first.students.map(function(item){
   item.status = statusById[item.id] || item.status;
   return "<tr><td>"+item.name+"</td><td>"+item.age+"</td><td>"+item.degree+"</td><td>"+item.status+"</td></tr>";
});

$('table#main tbody').html(items);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="main" cellspacing="2" border="1">
<thead>
  <tr>
    <th>Name</th>
    <th>Age</th>
    <th>Degree</th>
    <th>Stauts</th>
  </tr>
</thead>
<tbody>
</tbody>
</table>
</tbody>

</table>
Answer:2

I want to execute javascript file which is on another server and get the output of that script from my javascript code. Is there any way of doing this? Thanks in advance.

I want to execute javascript file which is on another server and get the output of that script from my javascript code. Is there any way of doing this? Thanks in advance.

  1. execute script with sudo
  2. execute script with another user
  3. execute script with crontab
  4. execute script with ansible
  5. execute script with bash
  6. execute script with ssh
  7. execute script with sqlplus
  8. execute script with powershell
  9. execute script with sqlcmd
  10. execute script with cron
  11. execute script with python
  12. execute script with node
  13. execute script with parameters powershell
  14. execute script with user
  15. execute script with curl
  16. execute script with putty
  17. execute script with sh
  18. execute script with psql
  19. execute script with selenium python
  20. execute script with ksh

If I have a cloud function like this, will the function setData() always execute until the end of the function(console either "successfully set data!" or "could not set data")? Because I have a ...

If I have a cloud function like this, will the function setData() always execute until the end of the function(console either "successfully set data!" or "could not set data")? Because I have a ...

  1. firebase cloud functions examples
  2. firebase cloud functions python
  3. firebase cloud functions tutorial
  4. firebase cloud functions environment variables
  5. firebase cloud functions pricing
  6. firebase cloud functions authentication
  7. firebase cloud functions triggers
  8. firebase cloud functions http request
  9. firebase cloud functions cors
  10. firebase cloud functions send email
  11. firebase cloud functions firestore
  12. firebase cloud functions node version
  13. firebase cloud functions schedule
  14. firebase cloud functions logging
  15. firebase cloud functions express
  16. firebase cloud functions flutter
  17. firebase cloud functions api
  18. firebase cloud functions emulator
  19. firebase cloud functions golang
  20. firebase cloud functions auth

i have a large list and i want to load it as the user scroll down the select field but how can i get the scroll event in mat-select there is no event that fire the scroll event. <mat-form-field&...

i have a large list and i want to load it as the user scroll down the select field but how can i get the scroll event in mat-select there is no event that fire the scroll event. <mat-form-field&...

  1. scroll event angular 7
  2. scroll event angular 8
  3. scroll event angular 6
  4. scroll event angular
  5. scroll event angular 4
  6. scroll event angular 5
  7. scroll event angular 2
  8. scroll event in angularjs
  9. window scroll event angular
  10. scroll end event angular 2
  11. get scroll event angular
  12. window scroll event angular 4
  13. div scroll event angular 6
  14. scroll down event angular
  15. listen scroll event angular
  16. trigger scroll event angular
  17. window scroll event angular 7
  18. mouse scroll event angular
  19. div scroll event angular 2
  20. scroll bottom event angular

Currently i am using chart.js but not able to make chart like following in which the bar is on the dotted line. I used like this JSFIDDLE Please suggest me some resource so that i can produce the ...

Currently i am using chart.js but not able to make chart like following in which the bar is on the dotted line. I used like this JSFIDDLE Please suggest me some resource so that i can produce the ...