Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
 let dataArray = [
 {size: 1180160, category: "Keswick", index: 1},
 {size: 1059328, category: "HCOPA", index: 2},
 {size: 30720, category: "HCOPA", index: 3},
 {size: 493056, category: "Darhan Saluja", index: 4},
 {size: 267776, category: "CRSA", index: 5},
 {size: 328704, category: "Arundel", index: 6},
 {size: 73216, category: "Arundel", index: 7}
 ]
 
var d = dataArray.reduce(function (Objects, data, index) { 
  console.log(Objects)
  if (data.category in Objects) {
    Objects[data.category]++;
  }
  else {
    Objects[data.category] = 1;
  }
  dataArray[index].counts = Objects[data.category];
  return Objects;
}, {});
console.log(dataArray)
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers