I have an object like below
var score = { 'A': 1, 'B': 2, 'C': 1 };
I want to create another object with key, value swapped and same valued keys grouped together, like below.
{ 1:['A', 'C'], 2: 'B' };
I dont want the single values, like 'B', inside an array. I want them alone. Please help.
Hi thanks for the answers. Finally to remove the array syntax if there is only one element i did the following.
$.each(obj, function(key, arr){
if(arr.length == 1){
obj[key] = arr[0]
}
});