score:3

Accepted answer

You might be looking for d3.group:

jsonData = [
  {vid: "General uneven corrosion", ver: "95"}, 
  {vid: "General uneven corrosion", ver: "95"},
  {vid: "General uneven corrosion", ver: "80"},
  {vid: "General uneven corrosion", ver: "80"},
  {vid: "General uneven corrosion", ver: "60"},
  {vid: "General uneven corrosion", ver: "20"},
  {vid: "General uneven corrosion", ver: "20"},
  {vid: "Increase in strength characteristics", ver: "80"},
  {vid: "Increase in strength characteristics", ver: "40"},
  {vid: "Increase in strength characteristics", ver: "40"},
  {vid: "Increase in hardness", ver: "95"},
  {vid: "Increase in hardness", ver: "60"},
  {vid: "Increase in hardness", ver: "40"},
  {vid: "Decreased ductility", ver: "60"},
  {vid: "Decreased ductility", ver: "60"},
  {vid: "Decreased ductility", ver: "60"},
  {vid: "Decreased ductility", ver: "60"},
  {vid: "Decreased ductility", ver: "40"},
  {vid: "Decreased ductility", ver: "40"},
  {vid: "Decreased ductility", ver: "20"}
];

let grouped = d3.group(jsonData, d => d.vid);

let fltrd = Array.from(grouped, ([k, v]) => {
  return {
    "state": k,
    "stats": v.map(d => +d.ver)
  }
});

console.log(fltrd);
<script src="https://d3js.org/d3.v6.min.js"></script>

You can do this without D3 though:

let fltrd = [];

let groups = Array.from(new Set(jsonData.map(k => k.vid)))

groups.map(k => 
    fltrd.push({
      "state": k,
      "stats": jsonData.filter(j => j.vid == k).map(j => +j.ver)
    })
  );

Related Query