What I want is that in the following arrangement when a value is entered in firstname
I bring all the fixes with that value but with its lastname
in an array:
var persons = [
{firstname : "Malcom", lastname: "Reynolds"},
{firstname : "Kaylee", lastname: "Frye"},
{firstname : "Jayne", lastname: "Cobb"},
{firstname : "Kaylee", lastname: "Frye"},
{firstname : "Jayne", lastname: "Freeman"},
{firstname : "Kaylee", lastname: "Frye"},
{firstname : "Jayne", lastname: "Summer"},
{firstname : "Jayne", lastname: "Doe"}
];
/*Loop*/
And that I bring them looked like this (in any way) and I would do it for all values of firstname
in the array:
result = 'Jayne'{"Cobb","Freeman","Summer","Doe"}
My progress:
var dict = { };
personas.forEach(function (obj) {
if (!dict[obj.firstname])
dict[obj.firstname] = [];
dict[obj.firstname].push(obj.lastname);
});