I have two arrays and need to change the order of elements in a way to be similar. by property c. i should get index of object of property c: 2 for example and place it to the right index in arrB . JavaScript
const arrA= [{
a: 1,
b: [{
c: 2,
d: 3
},
{
c: 5,
f: 6
}
]
},
{
a: 2,
b: [{
c: 2,
d: 3
},
{
c: 5,
f: 6
}
]
}
];
const arrB = [{
a: 1,
b: [{
c: 5,
f: 6
},
{
c: 2,
d: 3
},
]
},
{
a: 2,
b: [{
c: 5,
f: 6
},
{
c: 2,
d: 3
},
]
}
];
What I need is to sort arrB
in order of all elements in key b
to have the same order like in arrA
. in reality this object contain more fields and they aren't similar. but they have the same property c by which i should change the order
const arrB= [{
a: 1,
b: [{
c: 2,
d: 3
},
{
c: 5,
f: 6
}
]
},
{
a: 2,
b: [{
c: 2,
d: 3
},
{
c: 5,
f: 6
}
]
}
];