let number = parseInt('4'); const data = ['0 1','0 2','1 2','3 4']; let i = 0; const obj = {}; while(number--){ let row = data[i].split(' '); let index = row[0]; let value = parseInt(row[1]); console.log(`${index} ${value}`); if(Object.keys(obj).includes(index)){ obj[index]+=value; }else{ obj[index] = value; } i++; } for(let item of Object.entries(obj)){ console.log(item.toString().replace(',',' ')) } let ccc = ['1234','4556'] console.log(ccc.join(',,,'))