Sunday, 14 May 2017

Cannot understand this Js code

I am new to NodeJs comming from a Java and Angular Typescript Background.

Some one has written this code that i am not able to understand can you please help , tried a lot of console.logs but i am not able to grasp the syntax.\

function toMap(arr, key) {
  var map = {};
  console.log("Key is"+ key);
  if (arr) {
    for (var i=0; i<arr.length; i++) {
      map[arr[i][key]] = arr[i];
    }
  }

  return map;
}

The arr is a array of objects that is comming from the database and the id is a key and the value passed here is 'id'



via INFOSYS

No comments:

Post a Comment