thanks to another post I could mange a step ahead in what I taught was an easy process to do.. but it seems I cannot manage a proper way to merge two arrays into one, by "grouping" per an "id" common field...
Below is my one array:
// editedItem.extra_tools ///
0:
{
extra_tool_password: "tool data password"
extra_tool_username: "tool data username"
id_extra_tool: "8"
},
1:
{
extra_tool_password: "tool data password"
extra_tool_username: "tool data username"
id_extra_tool: "1"
},
2:
{
extra_tool_password: "tool data password"
extra_tool_username: "tool data username"
id_extra_tool: "7"
}
this should be merged, via id_extra_tool to:
// this.extras //
0:
{
extra_params: 1
extra_tool_name: "tool 1"
extra_tool_password: ""
extra_tool_username: ""
id_extra_tool: 1
}
1:
{
extra_params: 1
extra_tool_name: "tool 2"
extra_tool_password: ""
extra_tool_username: ""
id_extra_tool: 7
}
{
2:
extra_params: 0
extra_tool_name: "tool 3"
extra_tool_password: ""
extra_tool_username: ""
id_extra_tool: 8
to get a
//mergedArray //
if (this.editedItem.extra_tools.length) {
var mergedArray = []
this.editedItem.extra_tools.map(x => {
this.extras.map(y => {
if (x.id_extra_tool === y.id_extra_tool) {
mergedArray.push(Object.assign(x, y))
}
})
})
so the final array should contain "full" data from each array, completing each item merging data by id_extra_tool
// merged //
0:
{
extra_params: // TAKEN_BY: "Extras"
extra_tool_name: // TAKEN_BY: "Extras"
extra_tool_password:// TAKEN_BY: "extra_tools"
extra_tool_username: // TAKEN_BY: "extra_tools"
id_extra_tool: 1
}
1:
{
extra_params: // TAKEN_BY: "Extras"
extra_tool_name: // TAKEN_BY: "Extras"
extra_tool_password:// TAKEN_BY: "extra_tools"
extra_tool_username: // TAKEN_BY: "extra_tools"
id_extra_tool: 7
}
{
2:
extra_params: // TAKEN_BY: "Extras"
extra_tool_name: // TAKEN_BY: "Extras"
extra_tool_password:// TAKEN_BY: "extra_tools"
extra_tool_username: // TAKEN_BY: "extra_tools"
id_extra_tool: 8