[SOLVED] Change table into objects

Hy guys,

I’m actually using aldeed autoform + aldeed simpl-schema through a project.

I actually have this code :

console.log(Partners.find({'partner_details.is_customer': true}).map(s => s.name + ' ' + s.surname + ' | ' + s._id));

Which display :

[“Partenaire 1 Partenaire 1 | z6WScpCK7gvJropub”, “Partenaire 2 Partenaire 2 | g2sciqeEcL4WCL2db”]

I want to rework it to get this result :

{label:"Partenaire 1",value:"z6WScpCK7gvJropub"},{label:"Partenaire 2",value:"g2sciqeEcL4WCL2db"}

Does anyone know how should i do to complete this task ?

Thanks a lot for your help :slight_smile:

Happy coding,

B.

This can help you:

var partners = [];
Partners.find({'partner_details.is_customer': true}).forEach((doc) => {
                object = {};
                object.label = doc['name'] + ' ' + doc['surname'];
                object.value = doc['_id'];
                partners.push(object);
});
1 Like

Oh nice! Exactly what I need, it works perfectly, thanks! You saved me hours :smile:

or in a more functional and cleaner way:

const partners = Partners.find({'partner_details.is_customer': true}).map((doc) => ({
   label: doc['name'] + ' ' + doc['surname'],
   value: doc['_id']
}))
2 Likes

It seems better ! I’ll try it :slight_smile: Thanks for this !