I have an array of JSON objects like this
var dataSet1 = [{ "id": "1", "engine": "Trident", "browser": "Internet Explorer 4.0", "platform": "Win 95+", "version": "5", "grade": "X" }, { "id": "2", "engine": "Trident", "browser": "Internet Explorer 4.0", "platform": "Win 95+", "version": "5", "grade": "A" }, { "id": "3", "engine": "Trident", "browser": "Internet Explorer 4.0", "platform": "Win 95+", "version": "4", "grade": "X" }, { "id": "4", "engine": "Trident", "browser": "Internet Explorer 4.0", "platform": "Win 95+", "version": "5", "grade": "A" }];
I would like to skip this dataset and create a new array of objects that combine objects with similar properties of the class and keep a list of the corresponding id and version values ββthis way
OLD Objects with a grade property of 'X'
{ "id": "1", "engine": "Trident", "browser": "Internet Explorer 4.0", "platform": "Win 95+", "version": "5", "grade": "X" } { "id": "3", "engine": "Trident", "browser": "Internet Explorer 4.0", "platform": "Win 95+", "version": "4", "grade": "X" }
NEW An object with a 'grade' property equal to 'X'
{ "ids":{"id":"1","id":"3"} "engine": "Trident", "browser": "Internet Explorer 4.0", "platform": "Win 95+", "versions":{ "version":"4", "version":"5"} "grade": "X" }
I am sure that I need to use the $ .each and $ .grep function, for example,
$.each(dataSet1, function (index, value) { tsaGrade = dataSet1[index].grade; result = $.grep(dataSet1, function (e) { return e.grade == tsaGrade; })
and placing identifiers and versions in new arrays, but I'm losing information on how to prevent each loop from being excluded from the values ββthat are already grouped in the next loop using a dataset.