score:2

const response = `TAR_HEF_01 0
TAR_HEF_01 0
TAR_HEF_01 0
TAR_HEF_01 0
TAR_HEF_02 0
TAR_HEF_02 0
TAR_HEF_02 0
TAR_HEF_02 0
TAR_HEF_03 0
TAR_HEF_03 0
TAR_HEF_03 0
TAR_HEF_03 0
TAR_HEF_04 0
TAR_HEF_04 0
TAR_HEF_04 0
TAR_HEF_04 0
TAR_HEF_05 0
TAR_HEF_05 0
TAR_HEF_05 0
TAR_HEF_05 0
TAR_HEF_06 90
TAR_HEF_06 9
TAR_HEF_06 -200.8
TAR_HEF_06 214.9`;

//now split the lines and put them in splitLines array
let splitLines = response.split(/\r?\n/);
let map = [];

//loop through each line    
splitLines.forEach( (o, i) => {
  //parse the string to isolate month and value
  let parsed = o.split(" ");
  let parsedMonth = parsed[0];
  let parsedValue = parsed[1];
  //se map still doesn't contain the key parsedMonth
  if( typeof map[parsedMonth] === 'undefined' ){
    //create a new empty array bound to the key parsedMonth in map
    map[parsedMonth] = [];
  }
  //add the new value to the array bound to the parsedMonth in map
  map[parsedMonth].push(parsedValue);  
});

Related Query

More Query from same tag