Trying to merge duplicate keys of json array and build respective values in csv format.
A=[{a:1,b:2},{a:1,b:1},{a:1,b:6},{a:2,b:5},{a:2,b:3}]
Trying to convert in
A=[{a:'1',b:'2,1,6'},{a:2,b:'5,3'}]
code Which i tried
var existingIDs = [];
A= $.grep(A, function (v) {
if ($.inArray(v.a, existingIDs) !== -1) {
return v.b+= ',';
}
else {
existingIDs.push(v.a);
return true;
}
});
the output is returns like
A=[{a:1,b:2},{a:1,b:'1,'},{a:1,b:'6,'},{a:2,b:5},{a:2,b:'3,'}]