I want to store in a mysql table the following relations with a (DAD,SON) table that will look something like this:
| DAD || SON |
| mike. || june |
| mike || michael|
| june || elias |
| june || pepe |
and so on...
I have an unknown depth nested object that will look something like this:
const originalObject = {
Dad: 'mike',
sons: [
{
dad: 'june',
sons: [
{
dad: 'elias',
},
{
dad: 'pepe',
},
],
},
{
dad: 'michael',
sons: [
{
dad: 'elias',
},
{
dad: 'janister',
},
{
dad: 'pepe',
sons: [
{
dad: 'lester',
},
],
},
],
},
],
};
How can i make an array that looks like this :
const desiredArray = [
['mike', 'june'],
['mike', 'michael'],
['june', 'elias'],
['june', 'elias'],
etc,]
I have already converted the object to an array, but im not sure if it helps... The array right now is like:
const parsedObjectToArray =[ 'mike',[ [ 'june', [elias, pepe] ], [ 'michael', [elias, janister, pepe] ] ] ];
So, based on the originalObject or the parsedObjectToArray, how can i transform one of this to the desiredArray?? I have searched but i struggling hard! Thanks!