I need to filter an object array that contains duplicate titles but the description is unique. For e.g
[
{
"Title": "New York",
"Description": "A healthy and modernized transit system"
},
{
"Title": "New York",
"Description": "changed transit system"
},
{
"Title": "New York",
"Description": "xyz"
},
{
"Title": "New York",
"Description": "abc"
},
{
"Title": "chicago",
"Description": "jdfjjfj"
},
{
"Title": "chicago",
"Description": "abcdfdjf"
}
]
As you can see, the titles are duplicate whereas its description is unique.So can anybody please tell me how to filter this object array which filters out unique title and description being unique.
Basically the filtering should be as such that title comes first with its following unique descriptions.
var rs = {};
$.each(objs, function(i, obj) {
if (rs[obj.Title] === undefined) rs[obj.Title] = [];
rs[obj.Title].push(obj.Description);
});
Check it on jsFiddle: http://jsfiddle.net/U6qu4/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With